Page 1 of 1

Replace junk HTML entities in get_html_translation_table?

Posted: Thu Jan 22, 2009 7:34 pm
by JAB Creations
I'd like to replace the junk HTML entities in get_html_translation_table with the numeric versions.

So example I don't want...
< = <
> = >
& = &

I'd rather use...
< = <
> = >
& = &

I know we can use unset, here is what I've tried...

Code: Select all

<?php
$table = get_html_translation_table();
unset($table["<"]);
unset($table[">"]);
$table["<"] = <
$table[">"] = >
echo htmlspecialchars('<br />hello world<br />');
?>

Re: Replace junk HTML entities in get_html_translation_table?

Posted: Thu Jan 22, 2009 8:37 pm
by requinix
get_html_translation_table only tells you what the table is. You can't change it.
Use strtr to do the replacement, not htmlspecialchars.

Re: Replace junk HTML entities in get_html_translation_table?

Posted: Thu Jan 22, 2009 9:41 pm
by JAB Creations
Good idea...here is a function I made that I'll use for this now. :mrgreen:

Code: Select all

<?php
function entity_convert($convert)
{
 $entity['&'] = '&';
 $entity['<'] = '<';
 $entity['>'] = '>';
 
 foreach($entity as $key=>$value) {$convert=str_replace($key,$value,$convert);}
 return $convert;
}
 
$s = "<&><&>";
echo entity_convert($s);
?>