note 91895 modified in function.htmlentities by thiago
| From: | thiago@php.net | Date: | Wed, 01 Jul 2009 12:28:59 +0000 |
| Subject: | note 91895 modified in function.htmlentities by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-157766@lists.php.net to get a copy of this message | ||
Hello, I found a great function when you need a way to encode content from the database as numeric
entity references, as thatâs a safe way to use high characters and special characters in an xml
document, like in an RSS feed.
<?php
function xml_character_encode($string, $trans='') {
$trans = (is_array($trans)) ? $trans : get_html_translation_table(HTML_ENTITIES, ENT_QUOTES);
foreach ($trans as $k=>$v)
$trans[$k]= "&#".ord($k).";";
return strtr($string, $trans);
}
?>
--was--
Hello, I found a great function when you need a way to encode content from the database as numeric
entity references, as thatâs a safe way to use high characters and special characters in an xml
document, like in an RSS feed.
function xml_character_encode($string, $trans='') {
$trans = (is_array($trans)) ? $trans : get_html_translation_table(HTML_ENTITIES, ENT_QUOTES);
foreach ($trans as $k=>$v)
$trans[$k]= "&#".ord($k).";";
return strtr($string, $trans);
}
http://php.net/manual/en/function.htmlentities.php