![](/img/trans.png)
[英]PHP: Character escaping not working with double quotes unless there is a <pre> tag?
[英]Escaping " with \ on an HTML tag is not working
我的最终代码如下:
<a href="/galleries/hairtinsels/hairtinsel/hairtinsels.jpg" rel="shadowbox[gallery]" title="Hair Tinsels, 24 Colour Choices, 36\" Long">
注意36\\"
部分- "
用\\
转义,所以它应该起作用,对吗? 不,在暗盒上,标题会显示以下内容:
闪亮金属丝,24种颜色选择,36 \\
这令人难以置信...有什么想法吗?
这是使用PHP中的addslashes()
函数进行转义的-该库是由PHP遍历数组生成的。
您需要为每个上下文使用正确的转义功能。 在HTML中,您确实需要htmlspecialchars()
。 双引号内的引号应为"
。 (带反斜杠的通用C字符串转义在HTML / XML / SGML中不起作用。)
通常,您也需要charset参数:
htmlspecialchars($string, ENT_QUOTES, "UTF-8");
// and ENT_QUOTES just in case you had single quote attributes
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.