note 99625 deleted from function.html-entity-decode by danbrown

From: Date: Fri, 27 Aug 2010 11:04:05 +0000
Subject: note 99625 deleted from function.html-entity-decode by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-172108@lists.php.net to get a copy of this message
Note Submitter: Matias Perrone ---- 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('&euro;'); 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; } ?>

« previous php.notes (#172108) next »