简体   繁体   中英

How do I put single quotes inside of other single quotes?

I have this code inside of a php echo, which is inside of an if statement. I need to do this line of code, but the quotes are giving me a problem. echo "

<a href="#' onclick='popup('popUpDiv')"><img src='$pic'></a>";

Then I tried to do this, where image.php was the code above, and I don't think the variable carries over.

<?php include 'image.php'; ?>

How would I go about fixing this?

And do you need the full page code?

You can surround them with different quotes in HTML (some of your HTML quotes were unbalanced). In PHP you'll have to escape the inner quotes:

echo "<a href=\"#\" onclick=\"popup('popUpDiv')\"><img src='$pic'></a>";

This:

$pic='image.jpg';
echo '<a href="#" onclick="popup(\'popUpDiv\')"><img src="'.$pic.'"></a>';

will produce this:

<a href="#" onclick="popup('popUpDiv')"><img src="image.jpg"></a>

But you should be acccesing the onclick event through the DOM (inside <script> or better yet an external js file) and not using an href with an # .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM