简体   繁体   中英

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"!';
$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>

您需要双引号:

$str = 'I\\\'m very "shock"!';

我会这样做:

$link = '<a Onclick="javascript(\''.addslashes($str).'\')" href="#">'.$str.'</a>'; 

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