Htmlentities () vs. htmlspecialchars()

htmlspecialchars()htmlentities()之间有什么区别?什么时候我应该用一种或另一种?

354844 次浏览

来自而且不会的PHP文档:

这个函数在所有方面都与htmlspecialchars()相同,除了htmlentities()之外,所有具有HTML字符实体等价的字符都被转换为这些实体。

来自htmlspecialchars函数的PHP文档:

某些字符在HTML中有特殊的意义,如果要保留它们的含义,就应该用HTML实体来表示。这个函数返回一个包含这些转换的字符串;所做的翻译是那些对日常web编程最有用的。如果需要翻译所有HTML字符实体,请使用htmlentities()

区别在于编码的内容。选项是所有(实体)或“特殊”字符,如&号、双引号和单引号、小于和大于(specialchars)。

只要可能,我更喜欢使用htmlspecialchars

例如:

    echo htmlentities('<Il était une fois un être>.');
// Output: &lt;Il &eacute;tait une fois un &ecirc;tre&gt;.
//                ^^^^^^^^                 ^^^^^^^


echo htmlspecialchars('<Il était une fois un être>.');
// Output: &lt;Il était une fois un être&gt;.
//                ^                 ^

您可能希望使用一些Unicode字符编码,例如utf - 8和htmlspecialchars。因为任何不需要为“所有适用的字符”生成“HTML实体”(这是htmlentities根据文档所做的),如果它已经在你的字符集中。

因为:

  • 有时在编写XML数据时,不能在XML文件中使用HTML实体。
  • 因为htmlentities替换的字符比htmlspecialchars多。这是不必要的,这会降低PHP脚本的效率,从而降低HTML代码的可读性。

只有当您的页面使用ASCII或LATIN-1等编码而不是UTF-8,并且您使用与页面不同的编码处理数据时,htmlentities才有必要。

htmlspecialchars ()进行最少的编码,以确保字符串不会被解析为HTML。这使得您的字符串比使用htmlentities ()编码所有具有编码的内容时更易于阅读。

htmlspecialchars可以使用:

  1. 当不需要编码所有有HTML等价物的字符时。

    如果您知道页面编码与文本特殊符号匹配,为什么要使用htmlentities呢?htmlspecialchars非常简单,并且生成更少的代码发送给客户端。

    例如:

    echo htmlentities('<Il était une fois un être>.');
    // Output: &lt;Il &eacute;tait une fois un &ecirc;tre&gt;.
    //                ^^^^^^^^                 ^^^^^^^
    
    
    echo htmlspecialchars('<Il était une fois un être>.');
    // Output: &lt;Il était une fois un être&gt;.
    //                ^                 ^
    

    第二个字符较短,如果设置ISO-8859-1字符集,则不会产生任何问题

  2. 当数据不仅通过浏览器处理(以避免解码HTML实体)时,

  3. 如果输出是XML(参见,答案由Artefacto)。

我刚刚发现了get_html_translation_table函数。你传递给它HTML_ENTITIESHTML_SPECIALCHARS,它会返回一个数组,里面是要编码的字符以及它们的编码方式。

当你只想让你的字符串是XML和HTML安全的时候,你应该使用htmlspecialchars($strText, ENT_QUOTES):

例如,encode

  • ,和;音箱;
  • “;来,“
  • & lt;来,lt;
  • >来,gt;
  • & # 039;, # 039;

但是,如果文本中还有Unicode或不常见符号的额外字符,则应该使用htmlentities()来确保它们在HTML页面中正确显示。

注:

  • & # 039;只会被htmlspecialchars()编码到'如果传入ENT_QUOTES选项。, # 039;是更安全的使用,然后&由于旧版本的Internet Explorer不支持'实体。
  • 从技术上讲,在不需要按照XML规范进行编码,但为了与<被编码。

这是用htmlentities编码的。

# EYZ0:

< p > ",& lt;> < br > ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ­ ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ 十一万一千一百一十一ÆC E E E E 我我我我ÐN O O O O O×ØU U U YÞß一一一一一一æc e e e e我我我我ðN O O O O O÷øU U UþYœ . r Š s r f r r r m r ~ r r Α Β Γ Δ Ε Ζ Η Θ Ι Κ Λ Μ Ν Ξ Ο Π Ρ Σ Τ Υ Φ Χ Ψ Ω Α Β Γ Δ Ε Ζ Η Θ Ι Κ Λ Μ Ν Ξ Ο Π Ρ ς Σ Τ υ φ χ ψ ω ϑ ϒ ϖ□‍` ` ` ` ` - - ` `," ` ` `†‡•…‰`″ℑ℘ℜ™ℵ←↑→↓ ∀∂∃∅∇∋∏∑−∗√∞∠∧∨∩∫∴~≅≈≠≡≤≥⊃⊄⊆⊇⊕⊗⊥⌈⌉⌊⌋⟨

这是用htmlspecialchars编码的。

# EYZ0:

”,& lt;>

htmlentities -将所有适用的字符转换为HTML实体。

htmlspecialchars -将特殊字符转换为HTML实体。

翻译执行以下翻译字符:

  • '&'(&字符)变成'&'
  • 当没有设置ENT_NOQUOTES时,'"'(双引号)变成'"'。
  • 只有当设置了ENT_QUOTES时,"'"(单引号)才会变成'''(或')
  • '<'(小于)变成'<'
  • '>'(大于)变成'>'

你可以检查下面的代码,以了解什么是htmlentities和htmlspecialchars:

https://gist.github.com/joko-wandiro/f5c935708d9c37d8940b

一个小例子,我需要在一个函数中索引2个客户端名称:

[1] => Altisoxxce Soluxxons S.à r.l.
[5] => Joxxson & Joxxson

我最初是$term = get_term_by('name', htmlentities($name), 'client');,这导致术语名只包括&号数组项(&),但不包括重音项。但是当我将变量设置更改为htmlspecialchars时,两者都能够通过函数运行。希望这能有所帮助!

**HTML Character Entity Reference Chart at W3.org**

https://dev.w3.org/html5/html-author/charref

&Tab;
&NewLine;
!
&excl;
"
&quot; &QUOT;
#
&num;
$
&dollar;
%
&percnt;
&
&amp; &AMP;
'
&apos;
(
&lpar;
)
&rpar;
*
&ast; &midast;
+
&plus;
,
&comma;
.
&period;
/
&sol;
:
&colon;
;
&semi;
<
&lt; &LT;
=
&equals;
>
&gt; &GT;
?
&quest;
@
&commat;
[
&lsqb; &lbrack;
\
&bsol;
]
&rsqb; &rbrack;
^
&Hat;
_
&lowbar;
`
&grave; &DiacriticalGrave;
{
&lcub; &lbrace;
|
&verbar; &vert; &VerticalLine;
}
&rcub; &rbrace;


&nbsp; &NonBreakingSpace;
¡
&iexcl;
¢
&cent;
£
&pound;
¤
&curren;
¥
&yen;
¦
&brvbar;
§
&sect;
¨
&Dot; &die; &DoubleDot; &uml;
©
&copy; &COPY;
ª
&ordf;
«
&laquo;
¬
&not;
&shy;
®
&reg; &circledR; &REG;
¯
&macr; &OverBar; &strns;
°
&deg;
±
&plusmn; &pm; &PlusMinus;
²
&sup2;
³
&sup3;
´
&acute; &DiacriticalAcute;
µ
&micro;
¶
&para;
·
&middot; &centerdot; &CenterDot;
¸
&cedil; &Cedilla;
¹
&sup1;
º
&ordm;
»
&raquo;
¼
&frac14;
½
&frac12; &half;
¾
&frac34;
¿
&iquest;
À
&Agrave;
Á
&Aacute;
Â
&Acirc;
Ã
&Atilde;
Ä
&Auml;
Å
&Aring;
Æ
&AElig;
Ç
&Ccedil;
È
&Egrave;
É
&Eacute;
Ê
&Ecirc;
Ë
&Euml;
Ì
&Igrave;
Í
&Iacute;
Î
&Icirc;
Ï
&Iuml;
Ð
&ETH;
Ñ
&Ntilde;
Ò
&Ograve;
Ó
&Oacute;
Ô
&Ocirc;
Õ
&Otilde;
Ö
&Ouml;
×
&times;
Ø
&Oslash;
Ù
&Ugrave;
Ú
&Uacute;
Û
&Ucirc;
Ü
&Uuml;
Ý
&Yacute;
Þ
&THORN;
ß
&szlig;
à
&agrave;
á
&aacute;
â
&acirc;
ã
&atilde;
ä
&auml;
å
&aring;
æ
&aelig;
ç
&ccedil;
è
&egrave;
é
&eacute;
ê
&ecirc;
ë
&euml;
ì
&igrave;
í
&iacute;
î
&icirc;
ï
&iuml;
ð
&eth;
ñ
&ntilde;
ò
&ograve;
ó
&oacute;
ô
&ocirc;
õ
&otilde;
ö
&ouml;
÷
&divide; &div;
ø
&oslash;
ù
&ugrave;
ú
&uacute;
û
&ucirc;
ü
&uuml;
ý
&yacute;
þ
&thorn;
ÿ
&yuml;
Ā
&Amacr;
ā
&amacr;
Ă
&Abreve;
ă
&abreve;
Ą
&Aogon;
ą
&aogon;
Ć
&Cacute;
ć
&cacute;
Ĉ
&Ccirc;
ĉ
&ccirc;
Ċ
&Cdot;
ċ
&cdot;
Č
&Ccaron;
č
&ccaron;
Ď
&Dcaron;
ď
&dcaron;
Đ
&Dstrok;
đ
&dstrok;
Ē
&Emacr;
ē
&emacr;
Ė
&Edot;
ė
&edot;
Ę
&Eogon;
ę
&eogon;
Ě
&Ecaron;
ě
&ecaron;
Ĝ
&Gcirc;
ĝ
&gcirc;
Ğ
&Gbreve;
ğ
&gbreve;
Ġ
&Gdot;
ġ
&gdot;
Ģ
&Gcedil;
Ĥ
&Hcirc;
ĥ
&hcirc;
Ħ
&Hstrok;
ħ
&hstrok;
Ĩ
&Itilde;
ĩ
&itilde;
Ī
&Imacr;
ī
&imacr;
Į
&Iogon;
į
&iogon;
İ
&Idot;
ı
&imath; &inodot;
IJ
&IJlig;
ij
&ijlig;
Ĵ
&Jcirc;
ĵ
&jcirc;
Ķ
&Kcedil;
ķ
&kcedil;
ĸ
&kgreen;
Ĺ
&Lacute;
ĺ
&lacute;
Ļ
&Lcedil;
ļ
&lcedil;
Ľ
&Lcaron;
ľ
&lcaron;
Ŀ
&Lmidot;
ŀ
&lmidot;
Ł
&Lstrok;
ł
&lstrok;
Ń
&Nacute;
ń
&nacute;
Ņ
&Ncedil;
ņ
&ncedil;
Ň
&Ncaron;
ň
&ncaron;
ʼn
&napos;
Ŋ
&ENG;
ŋ
&eng;
Ō
&Omacr;
ō
&omacr;
Ő
&Odblac;
ő
&odblac;
Œ
&OElig;
œ
&oelig;
Ŕ
&Racute;
ŕ
&racute;
Ŗ
&Rcedil;
ŗ
&rcedil;
Ř
&Rcaron;
ř
&rcaron;
Ś
&Sacute;
ś
&sacute;
Ŝ
&Scirc;
ŝ
&scirc;
Ş
&Scedil;
ş
&scedil;
Š
&Scaron;
š
&scaron;
Ţ
&Tcedil;
ţ
&tcedil;
Ť
&Tcaron;
ť
&tcaron;
Ŧ
&Tstrok;
ŧ
&tstrok;
Ũ
&Utilde;
ũ
&utilde;
Ū
&Umacr;
ū
&umacr;
Ŭ
&Ubreve;
ŭ
&ubreve;
Ů
&Uring;
ů
&uring;
Ű
&Udblac;
ű
&udblac;
Ų
&Uogon;
ų
&uogon;
Ŵ
&Wcirc;
ŵ
&wcirc;
Ŷ
&Ycirc;
ŷ
&ycirc;
Ÿ
&Yuml;
Ź
&Zacute;
ź
&zacute;
Ż
&Zdot;
ż
&zdot;
Ž
&Zcaron;
ž
&zcaron;
ƒ
&fnof;
Ƶ
&imped;
ǵ
&gacute;
ȷ
&jmath;
ˆ
&circ;
ˇ
&caron; &Hacek;
˘
&breve; &Breve;
˙
&dot; &DiacriticalDot;
˚
&ring;
˛
&ogon;
˜
&tilde; &DiacriticalTilde;
˝
&dblac; &DiacriticalDoubleAcute;
̑
&DownBreve;
̲
&UnderBar;
Α
&Alpha;
Β
&Beta;
Γ
&Gamma;
Δ
&Delta;
Ε
&Epsilon;
Ζ
&Zeta;
Η
&Eta;
Θ
&Theta;
Ι
&Iota;
Κ
&Kappa;
Λ
&Lambda;
Μ
&Mu;
Ν
&Nu;
Ξ
&Xi;
Ο
&Omicron;
Π
&Pi;
Ρ
&Rho;
Σ
&Sigma;
Τ
&Tau;
Υ
&Upsilon;
Φ
&Phi;
Χ
&Chi;
Ψ
&Psi;
Ω
&Omega;
α
&alpha;
β
&beta;
γ
&gamma;
δ
&delta;
ε
&epsiv; &varepsilon; &epsilon;
ζ
&zeta;
η
&eta;
θ
&theta;
ι
&iota;
κ
&kappa;
λ
&lambda;
μ
&mu;
ν
&nu;
ξ
&xi;
ο
&omicron;
π
&pi;
ρ
&rho;
ς
&sigmav; &varsigma; &sigmaf;
σ
&sigma;
τ
&tau;
υ
&upsi; &upsilon;
φ
&phi; &phiv; &varphi;
χ
&chi;
ψ
&psi;
ω
&omega;
ϑ
&thetav; &vartheta; &thetasym;
ϒ
&Upsi; &upsih;
ϕ
&straightphi;
ϖ
&piv; &varpi;
Ϝ
&Gammad;
ϝ
&gammad; &digamma;
ϰ
&kappav; &varkappa;
ϱ
&rhov; &varrho;
ϵ
&epsi; &straightepsilon;
϶
&bepsi; &backepsilon;
Ё
&IOcy;
Ђ
&DJcy;
Ѓ
&GJcy;
Є
&Jukcy;
Ѕ
&DScy;
І
&Iukcy;
Ї
&YIcy;
Ј
&Jsercy;
Љ
&LJcy;
Њ
&NJcy;
Ћ
&TSHcy;
Ќ
&KJcy;
Ў
&Ubrcy;
Џ
&DZcy;
А
&Acy;
Б
&Bcy;
В
&Vcy;
Г
&Gcy;
Д
&Dcy;
Е
&IEcy;
Ж
&ZHcy;
З
&Zcy;
И
&Icy;
Й
&Jcy;
К
&Kcy;
Л
&Lcy;
М
&Mcy;
Н
&Ncy;
О
&Ocy;
П
&Pcy;
Р
&Rcy;
С
&Scy;
Т
&Tcy;
У
&Ucy;
Ф
&Fcy;
Х
&KHcy;
Ц
&TScy;
Ч
&CHcy;
Ш
&SHcy;
Щ
&SHCHcy;
Ъ
&HARDcy;
Ы
&Ycy;
Ь
&SOFTcy;
Э
&Ecy;
Ю
&YUcy;
Я
&YAcy;
а
&acy;
б
&bcy;
в
&vcy;
г
&gcy;
д
&dcy;
е
&iecy;
ж
&zhcy;
з
&zcy;
и
&icy;
й
&jcy;
к
&kcy;
л
&lcy;
м
&mcy;
н
&ncy;
о
&ocy;
п
&pcy;
р
&rcy;
с
&scy;
т
&tcy;
у
&ucy;
ф
&fcy;
х
&khcy;
ц
&tscy;
ч
&chcy;
ш
&shcy;
щ
&shchcy;
ъ
&hardcy;
ы
&ycy;
ь
&softcy;
э
&ecy;
ю
&yucy;
я
&yacy;
ё
&iocy;
ђ
&djcy;
ѓ
&gjcy;
є
&jukcy;
ѕ
&dscy;
і
&iukcy;
ї
&yicy;
ј
&jsercy;
љ
&ljcy;
њ
&njcy;
ћ
&tshcy;
ќ
&kjcy;
ў
&ubrcy;
џ
&dzcy;
 
&ensp;
 
&emsp;
 
&emsp13;
 
&emsp14;
 
&numsp;
 
&puncsp;
 
&thinsp; &ThinSpace;
 
&hairsp; &VeryThinSpace;
​
&ZeroWidthSpace; &NegativeVeryThinSpace; &NegativeThinSpace; &NegativeMediumSpace; &NegativeThickSpace;
‌
&zwnj;
‍
&zwj;
‎
&lrm;
‏
&rlm;
‐
&hyphen; &dash;
–
&ndash;
—
&mdash;
―
&horbar;
‖
&Verbar; &Vert;
‘
&lsquo; &OpenCurlyQuote;
’
&rsquo; &rsquor; &CloseCurlyQuote;
‚
&lsquor; &sbquo;
“
&ldquo; &OpenCurlyDoubleQuote;
”
&rdquo; &rdquor; &CloseCurlyDoubleQuote;
„
&ldquor; &bdquo;
†
&dagger;
‡
&Dagger; &ddagger;
•
&bull; &bullet;
‥
&nldr;
…
&hellip; &mldr;
‰
&permil;
‱
&pertenk;
′
&prime;
″
&Prime;
‴
&tprime;
‵
&bprime; &backprime;
‹
&lsaquo;
›
&rsaquo;
‾
&oline;
⁁
&caret;
⁃
&hybull;
⁄
&frasl;
⁏
&bsemi;
⁗
&qprime;
 
&MediumSpace;
⁠
&NoBreak;
⁡
&ApplyFunction; &af;
⁢
&InvisibleTimes; &it;
⁣
&InvisibleComma; &ic;
€
&euro;
⃛
&tdot; &TripleDot;
⃜
&DotDot;
ℂ
&Copf; &complexes;
℅
&incare;
ℊ
&gscr;
ℋ
&hamilt; &HilbertSpace; &Hscr;
ℌ
&Hfr; &Poincareplane;
ℍ
&quaternions; &Hopf;
ℎ
&planckh;
ℏ
&planck; &hbar; &plankv; &hslash;
ℐ
&Iscr; &imagline;
ℑ
&image; &Im; &imagpart; &Ifr;
ℒ
&Lscr; &lagran; &Laplacetrf;
ℓ
&ell;
ℕ
&Nopf; &naturals;
№
&numero;
℗
&copysr;
℘
&weierp; &wp;
ℙ
&Popf; &primes;
ℚ
&rationals; &Qopf;
ℛ
&Rscr; &realine;
ℜ
&real; &Re; &realpart; &Rfr;
ℝ
&reals; &Ropf;
℞
&rx;
™
&trade; &TRADE;
ℤ
&integers; &Zopf;
Ω
&ohm;
℧
&mho;
ℨ
&Zfr; &zeetrf;
℩
&iiota;
Å
&angst;
ℬ
&bernou; &Bernoullis; &Bscr;
ℭ
&Cfr; &Cayleys;
ℯ
&escr;
ℰ
&Escr; &expectation;
ℱ
&Fscr; &Fouriertrf;
ℳ
&phmmat; &Mellintrf; &Mscr;
ℴ
&order; &orderof; &oscr;
ℵ
&alefsym; &aleph;
ℶ
&beth;
ℷ
&gimel;
ℸ
&daleth;
ⅅ
&CapitalDifferentialD; &DD;
ⅆ
&DifferentialD; &dd;
ⅇ
&ExponentialE; &exponentiale; &ee;
ⅈ
&ImaginaryI; &ii;
⅓
&frac13;
⅔
&frac23;
⅕
&frac15;
⅖
&frac25;
⅗
&frac35;
⅘
&frac45;
⅙
&frac16;
⅚
&frac56;
⅛
&frac18;
⅜
&frac38;
⅝
&frac58;
⅞
&frac78;
←
&larr; &leftarrow; &LeftArrow; &slarr; &ShortLeftArrow;
↑
&uarr; &uparrow; &UpArrow; &ShortUpArrow;
→
&rarr; &rightarrow; &RightArrow; &srarr; &ShortRightArrow;
↓
&darr; &downarrow; &DownArrow; &ShortDownArrow;
↔
&harr; &leftrightarrow; &LeftRightArrow;
↕
&varr; &updownarrow; &UpDownArrow;
↖
&nwarr; &UpperLeftArrow; &nwarrow;
↗
&nearr; &UpperRightArrow; &nearrow;
↘
&searr; &searrow; &LowerRightArrow;
↙
&swarr; &swarrow; &LowerLeftArrow;
↚
&nlarr; &nleftarrow;
↛
&nrarr; &nrightarrow;
↝
&rarrw; &rightsquigarrow;
↞
&Larr; &twoheadleftarrow;
↟
&Uarr;
↠
&Rarr; &twoheadrightarrow;
↡
&Darr;
↢
&larrtl; &leftarrowtail;
↣
&rarrtl; &rightarrowtail;
↤
&LeftTeeArrow; &mapstoleft;
↥
&UpTeeArrow; &mapstoup;
↦
&map; &RightTeeArrow; &mapsto;
↧
&DownTeeArrow; &mapstodown;
↩
&larrhk; &hookleftarrow;
↪
&rarrhk; &hookrightarrow;
↫
&larrlp; &looparrowleft;
↬
&rarrlp; &looparrowright;
↭
&harrw; &leftrightsquigarrow;
↮
&nharr; &nleftrightarrow;
↰
&lsh; &Lsh;
↱
&rsh; &Rsh;
↲
&ldsh;
↳
&rdsh;
↵
&crarr;
↶
&cularr; &curvearrowleft;
↷
&curarr; &curvearrowright;
↺
&olarr; &circlearrowleft;
↻
&orarr; &circlearrowright;
↼
&lharu; &LeftVector; &leftharpoonup;
↽
&lhard; &leftharpoondown; &DownLeftVector;
↾
&uharr; &upharpoonright; &RightUpVector;
↿
&uharl; &upharpoonleft; &LeftUpVector;
⇀
&rharu; &RightVector; &rightharpoonup;
⇁
&rhard; &rightharpoondown; &DownRightVector;
⇂
&dharr; &RightDownVector; &downharpoonright;
⇃
&dharl; &LeftDownVector; &downharpoonleft;
⇄
&rlarr; &rightleftarrows; &RightArrowLeftArrow;
⇅
&udarr; &UpArrowDownArrow;
⇆
&lrarr; &leftrightarrows; &LeftArrowRightArrow;
⇇
&llarr; &leftleftarrows;
⇈
&uuarr; &upuparrows;
⇉
&rrarr; &rightrightarrows;
⇊
&ddarr; &downdownarrows;
⇋
&lrhar; &ReverseEquilibrium; &leftrightharpoons;
⇌
&rlhar; &rightleftharpoons; &Equilibrium;
⇍
&nlArr; &nLeftarrow;
⇎
&nhArr; &nLeftrightarrow;
⇏
&nrArr; &nRightarrow;
⇐
&lArr; &Leftarrow; &DoubleLeftArrow;
⇑
&uArr; &Uparrow; &DoubleUpArrow;
⇒
&rArr; &Rightarrow; &Implies; &DoubleRightArrow;
⇓
&dArr; &Downarrow; &DoubleDownArrow;
⇔
&hArr; &Leftrightarrow; &DoubleLeftRightArrow; &iff;
⇕
&vArr; &Updownarrow; &DoubleUpDownArrow;
⇖
&nwArr;
⇗
&neArr;
⇘
&seArr;
⇙
&swArr;
⇚
&lAarr; &Lleftarrow;
⇛
&rAarr; &Rrightarrow;
⇝
&zigrarr;
⇤
&larrb; &LeftArrowBar;
⇥
&rarrb; &RightArrowBar;
⇵
&duarr; &DownArrowUpArrow;
⇽
&loarr;
⇾
&roarr;
⇿
&hoarr;
∀
&forall; &ForAll;
∁
&comp; &complement;
∂
&part; &PartialD;
∃
&exist; &Exists;
∄
&nexist; &NotExists; &nexists;
∅
&empty; &emptyset; &emptyv; &varnothing;
∇
&nabla; &Del;
∈
&isin; &isinv; &Element; &in;
∉
&notin; &NotElement; &notinva;
∋
&niv; &ReverseElement; &ni; &SuchThat;
∌
&notni; &notniva; &NotReverseElement;
∏
&prod; &Product;
∐
&coprod; &Coproduct;
∑
&sum; &Sum;
−
&minus;
∓
&mnplus; &mp; &MinusPlus;
∔
&plusdo; &dotplus;
∖
&setmn; &setminus; &Backslash; &ssetmn; &smallsetminus;
∗
&lowast;
∘
&compfn; &SmallCircle;
√
&radic; &Sqrt;
∝
&prop; &propto; &Proportional; &vprop; &varpropto;
∞
&infin;
∟
&angrt;
∠
&ang; &angle;
∡
&angmsd; &measuredangle;
∢
&angsph;
∣
&mid; &VerticalBar; &smid; &shortmid;
∤
&nmid; &NotVerticalBar; &nsmid; &nshortmid;
∥
&par; &parallel; &DoubleVerticalBar; &spar; &shortparallel;
∦
&npar; &nparallel; &NotDoubleVerticalBar; &nspar; &nshortparallel;
∧
&and; &wedge;
∨
&or; &vee;
∩
&cap;
∪
&cup;
∫
&int; &Integral;
∬
&Int;
∭
&tint; &iiint;
∮
&conint; &oint; &ContourIntegral;
∯
&Conint; &DoubleContourIntegral;
∰
&Cconint;
∱
&cwint;
∲
&cwconint; &ClockwiseContourIntegral;
∳
&awconint; &CounterClockwiseContourIntegral;
∴
&there4; &therefore; &Therefore;
∵
&becaus; &because; &Because;
∶
&ratio;
∷
&Colon; &Proportion;
∸
&minusd; &dotminus;
∺
&mDDot;
∻
&homtht;
∼
&sim; &Tilde; &thksim; &thicksim;
∽
&bsim; &backsim;
∾
&ac; &mstpos;
∿
&acd;
≀
&wreath; &VerticalTilde; &wr;
≁
&nsim; &NotTilde;
≂
&esim; &EqualTilde; &eqsim;
≃
&sime; &TildeEqual; &simeq;
≄
&nsime; &nsimeq; &NotTildeEqual;
≅
&cong; &TildeFullEqual;
≆
&simne;
≇
&ncong; &NotTildeFullEqual;
≈
&asymp; &ap; &TildeTilde; &approx; &thkap; &thickapprox;
≉
&nap; &NotTildeTilde; &napprox;
≊
&ape; &approxeq;
≋
&apid;
≌
&bcong; &backcong;
≍
&asympeq; &CupCap;
≎
&bump; &HumpDownHump; &Bumpeq;
≏
&bumpe; &HumpEqual; &bumpeq;
≐
&esdot; &DotEqual; &doteq;
≑
&eDot; &doteqdot;
≒
&efDot; &fallingdotseq;
≓
&erDot; &risingdotseq;
≔
&colone; &coloneq; &Assign;
≕
&ecolon; &eqcolon;
≖
&ecir; &eqcirc;
≗
&cire; &circeq;
≙
&wedgeq;
≚
&veeeq;
≜
&trie; &triangleq;
≟
&equest; &questeq;
≠
&ne; &NotEqual;
≡
&equiv; &Congruent;
≢
&nequiv; &NotCongruent;
≤
&le; &leq;
≥
&ge; &GreaterEqual; &geq;
≦
&lE; &LessFullEqual; &leqq;
≧
&gE; &GreaterFullEqual; &geqq;
≨
&lnE; &lneqq;
≩
&gnE; &gneqq;
≪
&Lt; &NestedLessLess; &ll;
≫
&Gt; &NestedGreaterGreater; &gg;
≬
&twixt; &between;
≭
&NotCupCap;
≮
&nlt; &NotLess; &nless;
≯
&ngt; &NotGreater; &ngtr;
≰
&nle; &NotLessEqual; &nleq;
≱
&nge; &NotGreaterEqual; &ngeq;
≲
&lsim; &LessTilde; &lesssim;
≳
&gsim; &gtrsim; &GreaterTilde;
≴
&nlsim; &NotLessTilde;
≵
&ngsim; &NotGreaterTilde;
≶
&lg; &lessgtr; &LessGreater;
≷
&gl; &gtrless; &GreaterLess;
≸
&ntlg; &NotLessGreater;
≹
&ntgl; &NotGreaterLess;
≺
&pr; &Precedes; &prec;
≻
&sc; &Succeeds; &succ;
≼
&prcue; &PrecedesSlantEqual; &preccurlyeq;
≽
&sccue; &SucceedsSlantEqual; &succcurlyeq;
≾
&prsim; &precsim; &PrecedesTilde;
≿
&scsim; &succsim; &SucceedsTilde;
⊀
&npr; &nprec; &NotPrecedes;
⊁
&nsc; &nsucc; &NotSucceeds;
⊂
&sub; &subset;
⊃
&sup; &supset; &Superset;
⊄
&nsub;
⊅
&nsup;
⊆
&sube; &SubsetEqual; &subseteq;
⊇
&supe; &supseteq; &SupersetEqual;
⊈
&nsube; &nsubseteq; &NotSubsetEqual;
⊉
&nsupe; &nsupseteq; &NotSupersetEqual;
⊊
&subne; &subsetneq;
⊋
&supne; &supsetneq;
⊍
&cupdot;
⊎
&uplus; &UnionPlus;
⊏
&sqsub; &SquareSubset; &sqsubset;
⊐
&sqsup; &SquareSuperset; &sqsupset;
⊑
&sqsube; &SquareSubsetEqual; &sqsubseteq;
⊒
&sqsupe; &SquareSupersetEqual; &sqsupseteq;
⊓
&sqcap; &SquareIntersection;
⊔
&sqcup; &SquareUnion;
⊕
&oplus; &CirclePlus;
⊖
&ominus; &CircleMinus;
⊗
&otimes; &CircleTimes;
⊘
&osol;
⊙
&odot; &CircleDot;
⊚
&ocir; &circledcirc;
⊛
&oast; &circledast;
⊝
&odash; &circleddash;
⊞
&plusb; &boxplus;
⊟
&minusb; &boxminus;
⊠
&timesb; &boxtimes;
⊡
&sdotb; &dotsquare;
⊢
&vdash; &RightTee;
⊣
&dashv; &LeftTee;
⊤
&top; &DownTee;
⊥
&bottom; &bot; &perp; &UpTee;
⊧
&models;
⊨
&vDash; &DoubleRightTee;
⊩
&Vdash;
⊪
&Vvdash;
⊫
&VDash;
⊬
&nvdash;
⊭
&nvDash;
⊮
&nVdash;
⊯
&nVDash;
⊰
&prurel;
⊲
&vltri; &vartriangleleft; &LeftTriangle;
⊳
&vrtri; &vartriangleright; &RightTriangle;
⊴
&ltrie; &trianglelefteq; &LeftTriangleEqual;
⊵
&rtrie; &trianglerighteq; &RightTriangleEqual;
⊶
&origof;
⊷
&imof;
⊸
&mumap; &multimap;
⊹
&hercon;
⊺
&intcal; &intercal;
⊻
&veebar;
⊽
&barvee;
⊾
&angrtvb;
⊿
&lrtri;
⋀
&xwedge; &Wedge; &bigwedge;
⋁
&xvee; &Vee; &bigvee;
⋂
&xcap; &Intersection; &bigcap;
⋃
&xcup; &Union; &bigcup;
⋄
&diam; &diamond; &Diamond;
⋅
&sdot;
⋆
&sstarf; &Star;
⋇
&divonx; &divideontimes;
⋈
&bowtie;
⋉
&ltimes;
⋊
&rtimes;
⋋
&lthree; &leftthreetimes;
⋌
&rthree; &rightthreetimes;
⋍
&bsime; &backsimeq;
⋎
&cuvee; &curlyvee;
⋏
&cuwed; &curlywedge;
⋐
&Sub; &Subset;
⋑
&Sup; &Supset;
⋒
&Cap;
⋓
&Cup;
⋔
&fork; &pitchfork;
⋕
&epar;
⋖
&ltdot; &lessdot;
⋗
&gtdot; &gtrdot;
⋘
&Ll;
⋙
&Gg; &ggg;
⋚
&leg; &LessEqualGreater; &lesseqgtr;
⋛
&gel; &gtreqless; &GreaterEqualLess;
⋞
&cuepr; &curlyeqprec;
⋟
&cuesc; &curlyeqsucc;
⋠
&nprcue; &NotPrecedesSlantEqual;
⋡
&nsccue; &NotSucceedsSlantEqual;
⋢
&nsqsube; &NotSquareSubsetEqual;
⋣
&nsqsupe; &NotSquareSupersetEqual;
⋦
&lnsim;
⋧
&gnsim;
⋨
&prnsim; &precnsim;
⋩
&scnsim; &succnsim;
⋪
&nltri; &ntriangleleft; &NotLeftTriangle;
⋫
&nrtri; &ntriangleright; &NotRightTriangle;
⋬
&nltrie; &ntrianglelefteq; &NotLeftTriangleEqual;
⋭
&nrtrie; &ntrianglerighteq; &NotRightTriangleEqual;
⋮
&vellip;
⋯
&ctdot;
⋰
&utdot;
⋱
&dtdot;
⋲
&disin;
⋳
&isinsv;
⋴
&isins;
⋵
&isindot;
⋶
&notinvc;
⋷
&notinvb;
⋹
&isinE;
⋺
&nisd;
⋻
&xnis;
⋼
&nis;
⋽
&notnivc;
⋾
&notnivb;
⌅
&barwed; &barwedge;
⌆
&Barwed; &doublebarwedge;
⌈
&lceil; &LeftCeiling;
⌉
&rceil; &RightCeiling;
⌊
&lfloor; &LeftFloor;
⌋
&rfloor; &RightFloor;
⌌
&drcrop;
⌍
&dlcrop;
⌎
&urcrop;
⌏
&ulcrop;
⌐
&bnot;
⌒
&profline;
⌓
&profsurf;
⌕
&telrec;
⌖
&target;
⌜
&ulcorn; &ulcorner;
⌝
&urcorn; &urcorner;
⌞
&dlcorn; &llcorner;
⌟
&drcorn; &lrcorner;
⌢
&frown; &sfrown;
⌣
&smile; &ssmile;
⌭
&cylcty;
⌮
&profalar;
⌶
&topbot;
⌽
&ovbar;
⌿
&solbar;
⍼
&angzarr;
⎰
&lmoust; &lmoustache;
⎱
&rmoust; &rmoustache;
⎴
&tbrk; &OverBracket;
⎵
&bbrk; &UnderBracket;
⎶
&bbrktbrk;
⏜
&OverParenthesis;
⏝
&UnderParenthesis;
⏞
&OverBrace;
⏟
&UnderBrace;
⏢
&trpezium;
⏧
&elinters;
␣
&blank;
Ⓢ
&oS; &circledS;
─
&boxh; &HorizontalLine;
│
&boxv;
┌
&boxdr;
┐
&boxdl;
└
&boxur;
┘
&boxul;
├
&boxvr;
┤
&boxvl;
┬
&boxhd;
┴
&boxhu;
┼
&boxvh;
═
&boxH;
║
&boxV;
╒
&boxdR;
╓
&boxDr;
╔
&boxDR;
╕
&boxdL;
╖
&boxDl;
╗
&boxDL;
╘
&boxuR;
╙
&boxUr;
╚
&boxUR;
╛
&boxuL;
╜
&boxUl;
╝
&boxUL;
╞
&boxvR;
╟
&boxVr;
╠
&boxVR;
╡
&boxvL;
╢
&boxVl;
╣
&boxVL;
╤
&boxHd;
╥
&boxhD;
╦
&boxHD;
╧
&boxHu;
╨
&boxhU;
╩
&boxHU;
╪
&boxvH;
╫
&boxVh;
╬
&boxVH;
▀
&uhblk;
▄
&lhblk;
█
&block;
░
&blk14;
▒
&blk12;
▓
&blk34;
□
&squ; &square; &Square;
▪
&squf; &squarf; &blacksquare; &FilledVerySmallSquare;
▫
&EmptyVerySmallSquare;
▭
&rect;
▮
&marker;
▱
&fltns;
△
&xutri; &bigtriangleup;
▴
&utrif; &blacktriangle;
▵
&utri; &triangle;
▸
&rtrif; &blacktriangleright;
▹
&rtri; &triangleright;
▽
&xdtri; &bigtriangledown;
▾
&dtrif; &blacktriangledown;
▿
&dtri; &triangledown;
◂
&ltrif; &blacktriangleleft;
◃
&ltri; &triangleleft;
◊
&loz; &lozenge;
○
&cir;
◬
&tridot;
◯
&xcirc; &bigcirc;
◸
&ultri;
◹
&urtri;
◺
&lltri;
◻
&EmptySmallSquare;
◼
&FilledSmallSquare;
★
&starf; &bigstar;
☆
&star;
☎
&phone;
♀
&female;
♂
&male;
♠
&spades; &spadesuit;
♣
&clubs; &clubsuit;
♥
&hearts; &heartsuit;
♦
&diams; &diamondsuit;
♪
&sung;
♭
&flat;
♮
&natur; &natural;
♯
&sharp;
✓
&check; &checkmark;
✗
&cross;
✠
&malt; &maltese;
✶
&sext;
❘
&VerticalSeparator;
❲
&lbbrk;
❳
&rbbrk;
⟦
&lobrk; &LeftDoubleBracket;
⟧
&robrk; &RightDoubleBracket;
⟨
&lang; &LeftAngleBracket; &langle;
⟩
&rang; &RightAngleBracket; &rangle;
⟪
&Lang;
⟫
&Rang;
⟬
&loang;
⟭
&roang;
⟵
&xlarr; &longleftarrow; &LongLeftArrow;
⟶
&xrarr; &longrightarrow; &LongRightArrow;
⟷
&xharr; &longleftrightarrow; &LongLeftRightArrow;
⟸
&xlArr; &Longleftarrow; &DoubleLongLeftArrow;
⟹
&xrArr; &Longrightarrow; &DoubleLongRightArrow;
⟺
&xhArr; &Longleftrightarrow; &DoubleLongLeftRightArrow;
⟼
&xmap; &longmapsto;
⟿
&dzigrarr;
⤂
&nvlArr;
⤃
&nvrArr;
⤄
&nvHarr;
⤅
&Map;
⤌
&lbarr;
⤍
&rbarr; &bkarow;
⤎
&lBarr;
⤏
&rBarr; &dbkarow;
⤐
&RBarr; &drbkarow;
⤑
&DDotrahd;
⤒
&UpArrowBar;
⤓
&DownArrowBar;
⤖
&Rarrtl;
⤙
&latail;
⤚
&ratail;
⤛
&lAtail;
⤜
&rAtail;
⤝
&larrfs;
⤞
&rarrfs;
⤟
&larrbfs;
⤠
&rarrbfs;
⤣
&nwarhk;
⤤
&nearhk;
⤥
&searhk; &hksearow;
⤦
&swarhk; &hkswarow;
⤧
&nwnear;
⤨
&nesear; &toea;
⤩
&seswar; &tosa;
⤪
&swnwar;
⤳
&rarrc;
⤵
&cudarrr;
⤶
&ldca;
⤷
&rdca;
⤸
&cudarrl;
⤹
&larrpl;
⤼
&curarrm;
⤽
&cularrp;
⥅
&rarrpl;
⥈
&harrcir;
⥉
&Uarrocir;
⥊
&lurdshar;
⥋
&ldrushar;
⥎
&LeftRightVector;
⥏
&RightUpDownVector;
⥐
&DownLeftRightVector;
⥑
&LeftUpDownVector;
⥒
&LeftVectorBar;
⥓
&RightVectorBar;
⥔
&RightUpVectorBar;
⥕
&RightDownVectorBar;
⥖
&DownLeftVectorBar;
⥗
&DownRightVectorBar;
⥘
&LeftUpVectorBar;
⥙
&LeftDownVectorBar;
⥚
&LeftTeeVector;
⥛
&RightTeeVector;
⥜
&RightUpTeeVector;
⥝
&RightDownTeeVector;
⥞
&DownLeftTeeVector;
⥟
&DownRightTeeVector;
⥠
&LeftUpTeeVector;
⥡
&LeftDownTeeVector;
⥢
&lHar;
⥣
&uHar;
⥤
&rHar;
⥥
&dHar;
⥦
&luruhar;
⥧
&ldrdhar;
⥨
&ruluhar;
⥩
&rdldhar;
⥪
&lharul;
⥫
&llhard;
⥬
&rharul;
⥭
&lrhard;
⥮
&udhar; &UpEquilibrium;
⥯
&duhar; &ReverseUpEquilibrium;
⥰
&RoundImplies;
⥱
&erarr;
⥲
&simrarr;
⥳
&larrsim;
⥴
&rarrsim;
⥵
&rarrap;
⥶
&ltlarr;
⥸
&gtrarr;
⥹
&subrarr;
⥻
&suplarr;
⥼
&lfisht;
⥽
&rfisht;
⥾
&ufisht;
⥿
&dfisht;
⦅
&lopar;
⦆
&ropar;
⦋
&lbrke;
⦌
&rbrke;
⦍
&lbrkslu;
⦎
&rbrksld;
⦏
&lbrksld;
⦐
&rbrkslu;
⦑
&langd;
⦒

不完整,请跟踪完整文件的链接。

htmlspecialchars()和htmlentities()之间的区别非常小。让我们来看一些例子:

htmlspecialchars函数

:字符串$ string)有多个参数,其中第一个参数是字符串,所有其他参数(某些标志,某些编码等)都是可选的。htmlspecialchars函数将字符串中的特殊字符转换为HTML实体。例如,如果字符串中有& lt;br祝辞htmlspecialchars函数将把它转换为, lt;b和gt;。而像µ†等字符在HTML中没有特殊意义。因此,它们不会被htmlspecialchars函数函数转换为HTML实体,如下面的示例所示。

echo htmlspecialchars('An example <br>'); // This will print - An example &lt; br &gt;
echo htmlspecialchars('µ †');             // This will print -  µ †

而且不会

Htmlentities (string $string)非常类似于htmlspecialchars函数,并且有多个参数,其中第一个参数是字符串,所有其他参数都是可选的(某些标志,某些编码等)。与htmlspecialchars函数不同,而且不会不仅将字符串中的特殊字符转换为HTML实体,而且将所有适用的字符转换为HTML实体。

echo htmlentities('An example <br>'); // This will print - An example &lt; br &gt;
echo htmlentities('µ †');             // This will print -  &micro; &dagger;