note 44198 deleted from function.htmlentities by tomsommer
| From: | tomsommer@php.net | Date: | Sat, 17 Jul 2004 17:54:41 +0000 |
| Subject: | note 44198 deleted from function.htmlentities by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-73459@lists.php.net to get a copy of this message | ||
Note Submitter: pulstar@ig.com.br
----
If do you want to convert special characteres to their entities without affect the entities already
present in an HTML source code, try the function below:
<?php
function redo_entities($str) {
$str=str_replace("<","%lt%",$str);
$str=str_replace(">","%gt%",$str);
$str=str_replace("&","%amp%",$str);
if(version_compare(phpversion(),"4.3.0")>=0) {
$str=html_entity_decode($str,ENT_NOQUOTES);
} else {
$trans_table=get_html_translation_table(HTML_ENTITIES);
$trans_table=array_flip($trans_table);
strtr($str,$trans_table);
}
$str=htmlentities($str,ENT_NOQUOTES);
$str=str_replace("%lt%","<",$str);
$str=str_replace("%gt%",">",$str);
$str=str_replace("&","&",$str);
$str=str_replace("%amp%","&",$str);
return $str;
}
?>
Note: this function will not affect the quotes, "<" and ">".