htmlentities()与htmlspecialchars()

时间:2008-09-05 18:29:13

标签: php

htmlspecialchars()htmlentities()之间有何区别?我什么时候应该使用其中一种?

12 个答案:

答案 0 :(得分:370)

可以使用

htmlspecialchars

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

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

    例如:

    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(请参阅the answer by Artefacto)。

答案 1 :(得分:319)

来自htmlentities的PHP文档:

  

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

来自htmlspecialchars的PHP文档:

  

某些字符在HTML中具有特殊意义,如果要保留其含义,则应由HTML实体表示。此函数返回一个字符串,其中包含一些转换;所做的翻译是对日常网络编程最有用的翻译。如果您需要翻译所有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;.
    //                ^                 ^

答案 2 :(得分:91)

由于:

  • 有时您正在编写XML数据,而您无法在XML文件中使用HTML实体。
  • 因为htmlentities替换了比htmlspecialchars更多的字符。这是不必要的,使PHP脚本效率降低,并且生成的HTML代码可读性降低。

htmlentities仅在您的网页使用ASCII或LATIN-1等编码而不是UTF-8编码时才需要,并且您处理的数据编码与网页的编码不同。

答案 3 :(得分:87)

这是使用htmlentities编码的。

implode( "\t", array_values( get_html_translation_table( HTML_ENTITIES ) ) )

  

“&amp;&lt;&gt;
    ¡¢¥|§¨©ª«¯°¯°³³μμ······················································································································   ÌÍÏÏËÏÖÖØØØØØÖÖÖÖÖÖÖÖÖÖ××× þÿŒ   ŠΑ〜〜ΑΒΓΔΕΖΘΙΚΛΝΝΟΟΠΣΤΥΦΧμααβγδεζηθικλμνξοπρςσ τ   υφχψωθΥπ - - '',“”“†••...‰'”<>〜/€ℑ℘ℜℵℵ←↑→↓↔↵⇐⇑⇒⇓⇔   ∀∂∃∃∅∉∉ΠΠ - - √α∞∠∧∨∩∪∫∴∴≅≈≈=≤⊂⊂⊂⊃⊄⊆⊆⊇⊕⊗⊥⌈⌈⌈⌉⌊⌋⌋   ⟩◊♠♣♥♦

使用htmlspecialchars进行编码。

implode( "\t", array_values( get_html_translation_table( HTML_SPECIALCHARS ) ) )

  

“&amp;&lt;&gt;

答案 4 :(得分:16)

当您希望字符串是XML和HTML安全时,您应该使用htmlspecialchars($strText, ENT_QUOTES)

例如,编码

  • &安培;到&amp; amp;
  • “to&amp; quot;
  • &LT;到&amp; lt;
  • &GT;到&amp; gt;
  • 'to&amp;#039;

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

注意:

  • '只会被htmlspecialchars()编码为&amp;#039;如果传入ENT_QUOTES选项。&amp;#039;然后更安全地使用&amp;因为旧版本的Internet Explorer不支持&amp;实体。
  • 从技术上讲,&gt;不需要按照XML规范进行编码,但它通常也是为了与&lt;的要求保持一致而编码的。被编码。

答案 5 :(得分:13)

我刚刚发现了get_html_translation_table功能。您传递它HTML_ENTITIESHTML_SPECIALCHARS,它将返回一个数组,其中包含将要编码的字符以及它们的编码方式。

答案 6 :(得分:11)

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

答案 7 :(得分:7)

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

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

翻译在下面执行了翻译字符:

  • &#39;&安培;&#39; (&符号)成为&#39;&amp; amp;&#39;
  • &#39;&#34;&#39; (双引号)成为&#39;&amp; quot;&#39;当没有设置ENT_NOQUOTES时。
  • &#34;&#39;&#34; (单引号)成为&#39;&amp;#039;&#39; (或&#39;)仅在设置了ENT_QUOTES时。
  • &#39;&LT;&#39; (小于)成为&#39;&amp; lt;&#39;
  • &#39;&GT;&#39; (大于)变为&#39;&amp; gt;&#39;

您可以查看以下代码,了解有关htmlentities和htmlspecialchars的更多信息:

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

答案 8 :(得分:6)

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

答案 9 :(得分:2)

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

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

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

答案 10 :(得分:1)

**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;
Ă
&Abre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
&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;
ϖ
&pi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
 
&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;
⦒

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

答案 11 :(得分:1)

htmlspecialchars()和htmlentities()之间的差异很小。让我们看一些例子:

  

html特殊字符

htmlspecialchars(string $ string)采用多个参数,其中第一个参数是字符串,而所有其他参数(某些标志,某些编码等)是可选的。 htmlspecialchars 将字符串中的特殊字符转换为HTML实体。例如,如果您的字符串中包含
,则 htmlspecialchars 会将其转换为&lt; b&gt; 。而诸如µ†等字符在HTML中没有特殊意义。因此,它们不会通过 htmlspecialchars 函数转换为HTML实体,如下面的示例所示。

horse_controller
  

html实体

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

var express = require('express');
var router = express.Router();

 // Require controller modules.

var horse_controller = require('../controllers/horseController');

router.get('/', horse_controller);


module.exports = router;