note 69913 modified in function.htmlentities by danbrown
| From: | danbrown@php.net | Date: | Sun, 17 May 2009 16:55:32 +0000 |
| Subject: | note 69913 modified in function.htmlentities by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-154912@lists.php.net to get a copy of this message | ||
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 : & é $ à ç <
--was--
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 : & é $ à ç <
First method convert characters to decimal values.
Second will reverse the problem !!!
http://php.net/manual/en/function.htmlentities.php