php multi Quotation marks
I meet a headache problem. there are too many Quotation marks in my code make me headache.
I tried both of these method, but all the way are make links broken. I cheked it in chrome
, In elements
, I find the source code like what I add after print($link);
.
How to solve the problem? Thanks.
$str = 'I\'m very "shock"!';
开发者_Go百科$link=<<<EOT
<a Onclick="javascript('$str')" href="#">$str</a>'
EOT;
print($link); // <a onclick="javascript('I'm very " shock"!')"="" href="#">I'm very "shock"!</a>
OR
$str = 'I\'m very "shock"!';
$link = '<a Onclick="javascript(\''.$str.'\')" href="#">'.$str.'</a>';
print($link); //<a onclick="javascript('I'm very " shock"!')"="" href="#">I'm very "shock"!</a>
I would do this:
$link = '<a Onclick="javascript(\''.addslashes($str).'\')" href="#">'.$str.'</a>';
You need to double-escape your quotes :
$str = 'I\\\'m very "shock"!';
精彩评论