Home » Php » php – htmlentities() vs. htmlspecialchars()

php – htmlentities() vs. htmlspecialchars()

Posted by: admin February 22, 2020 Leave a comment

Questions:

What are the differences between htmlspecialchars() and htmlentities(). When should I use one or the other?

How to&Answers:

From the PHP documentation for htmlentities:

This function is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities.

From the PHP documentation for htmlspecialchars:

Certain characters have special significance in HTML, and should be represented by HTML entities if they are to preserve their meanings. This function returns a string with some of these conversions made; the translations made are those most useful for everyday web programming. If you require all HTML character entities to be translated, use htmlentities() instead.

The difference is what gets encoded. The choices are everything (entities) or “special” characters, like ampersand, double and single quotes, less than, and greater than (specialchars).

I prefer to use htmlspecialchars whenever possible.

For example:

    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;.
    //                ^                 ^

Answer:

htmlspecialchars may be used:

  1. When there is no need to encode all characters which have their HTML equivalents.

    If you know that the page encoding match the text special symbols, why would you use htmlentities? htmlspecialchars is much straightforward, and produce less code to send to the client.

    For example:

    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;.
    //                ^                 ^
    

    The second one is shorter, and does not cause any problems if ISO-8859-1 charset is set.

  2. When the data will be processed not only through a browser (to avoid decoding HTML entities),

  3. If the output is XML (see the answer by Artefacto).

Answer:

Because:

  • Sometimes you’re writing XML data, and you can’t use HTML entities in a XML file.
  • Because htmlentities substitutes more characters than htmlspecialchars. This is unnecessary, makes the PHP script less efficient and the resulting HTML code less readable.

htmlentities is only necessary if your pages use encodings such as ASCII or LATIN-1 instead of UTF-8 and you’re handling data with an encoding different from the page’s.

Answer:

This is being encoded with htmlentities.

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

” & < >
¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ­ ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ À Á Â Ã Ä Å Æ Ç È É Ê Ë
Ì Í Î Ï Ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ü Ý Þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ Œ
œ Š š Ÿ ƒ ˆ ˜ Α Β Γ Δ Ε Ζ Η Θ Ι Κ Λ Μ Ν Ξ Ο Π Ρ Σ Τ Υ Φ Χ Ψ Ω α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ ς σ τ
υ φ χ ψ ω ϑ ϒ ϖ       ‌ ‍ ‎ ‏ – — ‘ ’ ‚ “ ” „ † ‡ • … ‰ ′ ″ ‹ › ‾ ⁄ € ℑ ℘ ℜ ™ ℵ ← ↑ → ↓ ↔ ↵ ⇐ ⇑ ⇒ ⇓ ⇔
∀ ∂ ∃ ∅ ∇ ∈ ∉ ∋ ∏ ∑ − ∗ √ ∝ ∞ ∠ ∧ ∨ ∩ ∪ ∫ ∴ ∼ ≅ ≈ ≠ ≡ ≤ ≥ ⊂ ⊃ ⊄ ⊆ ⊇ ⊕ ⊗ ⊥ ⋅ ⌈ ⌉ ⌊ ⌋ ⟨
⟩ ◊ ♠ ♣ ♥ ♦

This is being encoded with htmlspecialchars.

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

” & < >

Answer:

You should use htmlspecialchars($strText, ENT_QUOTES) when you just want your string to be XML and HTML safe:

For example, encode

  • & to &amp;
  • " to &quot;
  • < to &lt;
  • > to &gt;
  • ' to '

However, if you also have additional characters that are Unicode or uncommon symbols in your text then you should use htmlentities() to ensure they show up properly in your HTML page.

Notes:

  • ' will only be encoded by htmlspecialchars() to ' if the ENT_QUOTES option is passed in. ' is safer to use then &apos; since older versions of Internet Explorer do not support the &apos; entity.
  • Technically, > does not need to be encoded as per the XML specification, but it is usually encoded too for consistency with the requirement of < being encoded.

Answer:

I just found out about the get_html_translation_table function. You pass it HTML_ENTITIES or HTML_SPECIALCHARS and it returns an array with the characters that will be encoded and how they will be encoded.

Answer:

htmlspecialchars () does the minimum amount of encoding to ensure that your string is not parsed as HTML. This leaves your string more human-readable than it would be if you used htmlentities () to encode absolutely everything that has an encoding.

Answer:

htmlentities — Convert all applicable characters to HTML entities.

htmlspecialchars — Convert special characters to HTML entities.

The translations performed translation characters on the below:

  • ‘&’ (ampersand) becomes ‘&amp;’
  • ‘”‘ (double quote) becomes ‘&quot;’ when ENT_NOQUOTES is not set.
  • “‘” (single quote) becomes ‘'’ (or ') only when ENT_QUOTES is set.
  • ‘<‘ (less than) becomes ‘&lt;’
  • ‘>’ (greater than) becomes ‘&gt;’

You can check the following code for more information about what’s htmlentities and htmlspecialchars:

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

Answer:

You probably want to use some Unicode character encoding, for example UTF-8, and htmlspecialchars. Because there isn’t any need to generate “HTML entities” for “all [the] applicable characters” (that is what htmlentities does according to the documentation) if it’s already in your character set.

Answer:

One small example, I needed to have 2 client names indexed in a function:

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

I originally $term = get_term_by('name', htmlentities($name), 'client'); which resulted in term names that only included the ampersand array item (&) but not the accented item. But when I changed the variable setting to htmlspecialchars both were able to run through the function. Hope this helps!

Answer:

**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; ⦒ 

Not fully, pls track the link for fully document.

Answer:

The differences between htmlspecialchars() and htmlentities() is very small. Lets see some examples:

htmlspecialchars

htmlspecialchars(string $string) takes multiple arguments where as the first argument is a string and all other arguments (certain flags, certain encodings etc. ) are optional. htmlspecialchars converts special characters in the string to HTML entities. For example if you have < br > in your string, htmlspecialchars will convert it into &lt; b &gt;. Whereas characters like µ † etc. have no special significance in HTML. So they will be not converted to HTML entities by htmlspecialchars function as shown in the below example.

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

htmlentities

htmlentities ( string $string) is very similar to htmlspecialchars and takes multiple arguments where as the first argument is a string and all other arguments are optional (certain flags, certain encodings etc.). Unlike htmlspecialchars, htmlentities converts not only special characters in the string to HTML entities but all applicable characters to HTML entities.

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