note 44198 added to function.htmlentities

From: Date: Sat, 17 Jul 2004 17:18:35 +0000
Subject: note 44198 added to function.htmlentities
Groups: php.notes 
Request: Send a blank email to php-notes+get-73457@lists.php.net to get a copy of this message
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;","%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("&amp;","&",$str); $str=str_replace("%amp%","&amp;",$str); return $str; } ?> Note: this function will not affect the quotes, "<" and ">". ---- Manual Page -- http://www.php.net/manual/en/function.htmlentities.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+44198 Delete -- http://master.php.net/manage/user-notes.php?action=delete+44198&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+44198&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#73457) next »