note 93892 added to function.htmlentities

From: Date: Mon, 05 Oct 2009 20:05:36 +0000
Subject: note 93892 added to function.htmlentities
Groups: php.notes 
Request: Send a blank email to php-notes+get-161373@lists.php.net to get a copy of this message
When happens that you want to encode special characters but not the HTML tags using this function you've two options: a) Build your own function and go replace by character; eg. <?php for($i = 0; $i < strlen($string); $i++){ switch(substr($string,$i,1)){ //..... A VERY HUGE switch here with all characters to encode. } } ?> b) use this function and simple restore the html tags afterwards. Which gives you a 6 line function as follow: <?php function keephtml($string){ $res = htmlentities($string); $res = str_replace("&lt;","<",$res); $res = str_replace("&gt;",">",$res); $res = str_replace("&quot;",'"',$res); $res = str_replace("&amp;",'&',$res); return $res; } ?> ---- Server IP: 209.41.74.194 Probable Submitter: 188.80.101.129 ---- Manual Page -- http://www.php.net/manual/en/function.htmlentities.php Edit -- https://master.php.net/note/edit/93892 Del: integrated -- https://master.php.net/note/delete/93892/integrated Del: useless -- https://master.php.net/note/delete/93892/useless Del: bad code -- https://master.php.net/note/delete/93892/bad+code Del: spam -- https://master.php.net/note/delete/93892/spam Del: non-english -- https://master.php.net/note/delete/93892/non-english Del: in docs -- https://master.php.net/note/delete/93892/in+docs Del: other reasons-- https://master.php.net/note/delete/93892 Reject -- https://master.php.net/note/reject/93892 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#161373) next »