Replace junk HTML entities in get_html_translation_table?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Replace junk HTML entities in get_html_translation_table?

Post 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 />');
?>
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Replace junk HTML entities in get_html_translation_table?

Post 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.
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Replace junk HTML entities in get_html_translation_table?

Post 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);
?>
Post Reply