1. 程式人生 > >html中的單引號、雙引號及其轉義使用

html中的單引號、雙引號及其轉義使用

在 (x)HTML 中,一些特殊字元應該進行 HTML 實體轉義。

常見的有:&(and)、"(雙引號)、'(單引號)、<(小於號)、>(大於號),這些在 (x)HTML 文件內容中應該分別轉換成:&amp;&quot;&#39;&lt; 和 &gt;

 IE 瀏覽器暫時不支援單引號的實體名稱,IE 瀏覽器暫時只支援單引號的實體編號

這也是 PHP htmlspecialchars 函式把單引號轉義成 &#39;,而不是 &apos; 的原因。

Character Entity Number Entity Name Description
" &#34; &quot; quotation mark
' &#39; &apos; (does not work in IE) apostrophe 
& &#38; &amp; ampersand
< &#60; &lt; less-than
> &#62; &gt; greater-than