note 69913 deleted from function.htmlentities by hholzgra
| From: | hholzgra@php.net | Date: | Thu, 02 Aug 2012 11:26:37 +0000 |
| Subject: | note 69913 deleted from function.htmlentities by hholzgra | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-189589@lists.php.net to get a copy of this message | ||
Note Submitter: eric.wallet at yahoo.fr
----
First method convert characters to decimal values.
Second will reverse the problem !!!
<?php
function htmlnumericentities($str){
return preg_replace('/[^!-%\x27-;=?-~ ]/e',
'"&#".ord("$0").chr(59)', $str);
}
function numericentitieshtml($str){
return utf8_encode(preg_replace('/&#(\d+);/e',
'chr(str_replace(";","",str_replace("&#","","$0")))',
$str));
}
echo (htmlnumericentities ("Ceci est un test : & é $ à ç <"));
echo ("<br/>\n");
echo (numericentitieshtml (htmlnumericentities ("Ceci est un test : & é $ à ç
<")));
?>
Output is :
Ceci est un test : & é $ à ç <<br/>
Ceci est un test : & é $ à ç <