[英]Help with PHP echo syntax with JS quotes
Here's a snippet of my echo command:这是我的 echo 命令的片段:
echo 'onclick="derp(',$url,$image_dir,$file,')'
It currently outputs something like this:它当前输出如下内容:
onclick="derp(foobar)
But, I want it to output something like this:但是,我想要它 output 是这样的:
onclick="derp('foobar')
Since PHP freaks out when you use quotes, I really don't know what to do.由于 PHP 在使用引号时会发疯,我真的不知道该怎么办。
echo 'onclick="derp(\'',$url,$image_dir,$file,'\')';
echo "onclick=\"derp(',$url,$image_dir,$file,')"
If possible use json_encode
and htmlspecialchars
to encode the values properly:如果可能,请使用json_encode
和htmlspecialchars
正确编码值:
$onclick = "derp(".json_encode($url.$image_dir.$file).")";
echo 'onclick="'.htmlspecialchars($onclick).'"';
echo 'onclick="derp(', "'", $url, $image_dir, $file, "'", ')';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.