note 93892 deleted from function.htmlentities by cmb

From: Date: Sun, 01 Dec 2019 08:30:29 +0000
Subject: note 93892 deleted from function.htmlentities by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-213294@lists.php.net to get a copy of this message
Note Submitter: sirarthur at sirarthur dot info ---- 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; } ?>

« previous php.notes (#213294) next »