note 83168 deleted from function.htmlentities by danbrown
| From: | danbrown@php.net | Date: | Sun, 17 May 2009 16:50:11 +0000 |
| Subject: | note 83168 deleted from function.htmlentities by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-154895@lists.php.net to get a copy of this message | ||
Note Submitter: eric at tillandsia dot nl
----
I don't know, but I get a lott of warnings about unknown html entities when I use the function:
htmlentities($str,HTML_ENTITIES,'UTF-8')
The function below works fine for me, just a replacement by a decimal coding.
A str_replace for each possible latin character in a string as in an earlier example using a hash
table is slowing down the script, because you go through the string for each latin character again.
In the example below, you will go through it only once.
function parseXMLcoding($string)
{
if ( strlen($string) == 0 )
return $string;
$string = preg_split("//", $string, -1, PREG_SPLIT_NO_EMPTY);
for ( $i = 0; $i < count($string); $i++ )
{
$dec = ord($string[$i]);
if ( $dec > 127 )
$string[$i] = '&#' . $dec . ';';
}
return implode('',$string);
}