![](/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.