note 99625 added to function.html-entity-decode
| From: | MatiasPerrone at osu1 dot php dot net | Date: | Fri, 27 Aug 2010 05:03:08 +0000 |
| Subject: | note 99625 added to function.html-entity-decode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-172107@lists.php.net to get a copy of this message | ||
Inspired on the post http://inanimatt.com/php-convert-entities.php,
I have make the following pair of functions, that replace the current PHP
"html_entity_decode".
use:
echo html_entity_decode_ext('€');
result: â¬
Works exactly like html_entity_decode, if the entity was not found is ignored, not converted.
The characters selected are the ones that exists on iso-8859-1 charset, like euro.
Tested on PHP 5.2.14.
<?php
function html_entity_decode_ext($string) {
return preg_replace_callback('/&([a-zA-Z][a-zA-Z0-9]+);/',
'decode_entity', $string);
}
function decode_entity($matches) {
static $table = array('quot' => '"','amp' =>
'&','lt' => '<','gt' =>
'>','OElig' => 'Å','oelig' =>
'Å','Scaron' => 'Å ','scaron' =>
'š','Yuml' => 'Ÿ','circ' =>
'Ë','tilde' => 'Ë','ensp' => '
','emsp' => ' ','ndash' =>
'â','mdash' => 'â','lsquo' =>
'â','rsquo' => 'â','sbquo' =>
'â','ldquo' => 'â','rdquo' =>
'â','bdquo' => 'â','dagger' =>
'â ','Dagger' => 'â¡','permil' =>
'â°','lsaquo' => 'â¹','rsaquo' =>
'âº','euro' => 'â¬','fnof' =>
'Æ','beta' => 'Ã','mu' =>
'µ','pi' => '¶','bull' =>
'â¢','hellip' => 'â¦','frasl' =>
'/','weierp' => 'P','image' =>
'I','real' => 'R','trade' =>
'â¢','empty' => 'Ã','minus' =>
'-','lowast' => '*','sim' =>
'~','asymp' => 'Ë','nbsp' => '
','iexcl' => '¡','cent' =>
'¢','pound' => '£','curren' =>
'¤','yen' => '¥','brvbar' =>
'¦','sect' => '§','uml' =>
'¨','copy' => '©','ordf' =>
'ª','laquo' => '«','not' =>
'¬','shy' => ' ','reg' =>
'®','macr' => '¯','deg' =>
'°','plusmn' => '±','sup2' =>
'²','sup3' => '³','acute' =>
'´','micro' => 'µ','para' =>
'¶','middot' => '·','cedil' =>
'¸','sup1' => '¹','ordm' =>
'º','raquo' => '»','frac14' =>
'¼','frac12' => '½','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' => 'Ã!
³','ocir
c' => 'ô','otilde' => 'õ','ouml' =>
'ö','divide' => '÷','oslash' =>
'ø','ugrave' => 'ù','uacute' =>
'ú','ucirc' => 'û','uuml' =>
'ü','yacute' => 'ý','thorn' =>
'þ');
// Entity not found? Destroy it.
return isset($table[$matches[1]]) ? $table[$matches[1]] : $matches;
}
?>
----
Server IP: 190.2.55.64
Probable Submitter: 201.253.86.217
----
Manual Page -- http://www.php.net/manual/en/function.html-entity-decode.php
Edit -- https://master.php.net/note/edit/99625
Del: integrated -- https://master.php.net/note/delete/99625/integrated
Del: useless -- https://master.php.net/note/delete/99625/useless
Del: bad code -- https://master.php.net/note/delete/99625/bad+code
Del: spam -- https://master.php.net/note/delete/99625/spam
Del: non-english -- https://master.php.net/note/delete/99625/non-english
Del: in docs -- https://master.php.net/note/delete/99625/in+docs
Del: other reasons-- https://master.php.net/note/delete/99625
Reject -- https://master.php.net/note/reject/99625
Search -- https://master.php.net/manage/user-notes.php