[英]Escaping " with \ on an HTML tag is not working
My final code looks like this: 我的最终代码如下:
<a href="/galleries/hairtinsels/hairtinsel/hairtinsels.jpg" rel="shadowbox[gallery]" title="Hair Tinsels, 24 Colour Choices, 36\" Long">
Note the 36\\"
part - the "
is escaped with a \\
so it should work, right? 注意
36\\"
部分- "
用\\
转义,所以它应该起作用,对吗? No, on shadowbox the title cuts off and just says: 不,在暗盒上,标题会显示以下内容:
Hair Tinsels, 24 Colour Choices, 36\\ 闪亮金属丝,24种颜色选择,36 \\
This is mind-boggling... any ideas? 这令人难以置信...有什么想法吗?
This was escaped using addslashes()
function in PHP - this gallery is generated by PHP looping through an array. 这是使用PHP中的
addslashes()
函数进行转义的-该库是由PHP遍历数组生成的。
You need the right escaping function for each context. 您需要为每个上下文使用正确的转义功能。 And within HTML, you do need
htmlspecialchars()
. 在HTML中,您确实需要
htmlspecialchars()
。 The quote within double quotes should be "
双引号内的引号应为
"
. 。 (The common C string escapes with the backslash don't work in HTML/XML/SGML.)
(带反斜杠的通用C字符串转义在HTML / XML / SGML中不起作用。)
Quite commonly you need the charset parameter too: 通常,您也需要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.