Search code examples
phputf-8html-entities

How to create a htmlentity of utf-8 `ł` (polish-L) in PHP?


What are the reasons of "ł" not being entity-able ?

and how would one do this for characters in general which are not in get_html_translation_table ?

How is the content of get_html_translation_table specified/defined ?

(talking only utf-8 here)

// control with 'ö'
php > echo htmlentities("ö",ENT_COMPAT,'utf-8');
ö

// test with 'ł'
php > echo htmlentities("ł",ENT_COMPAT,'utf-8');
ł

check get_html_translation_table:

php > var_dump(implode(',',array_keys(
                 get_html_translation_table(HTML_ENTITIES))));

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

PHP 5.6.12


Solution

  • You need to handle code as HTML 5 with the ENT_HTML5 flag.

    echo htmlentities("ł", ENT_COMPAT | ENT_HTML5, 'utf-8');