Posted by Janwillem Borleffs on 08/28/05 14:57
Jonathan Mcdougall wrote:
> Is there a php function which translates special characters to
> character codes?
> htmlentities() only translates to named codes (é).
>
You can use the translation table used by htmlentities() and
htmlspecialchars() as follows:
$table = get_html_translation_table(HTML_ENTITIES);
foreach (array_keys($table) as $k) {
$table[$k] = '&#' . ord($k) . ';';
}
And then apply it as the second argument to strtr():
$text = strtr($text, $table);
JW
Navigation:
[Reply to this message]
|