note 97891 deleted from function.htmlentities by cmb

From: Date: Sun, 01 Dec 2019 08:33:55 +0000
Subject: note 97891 deleted from function.htmlentities by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-213304@lists.php.net to get a copy of this message
Note Submitter: Wired ---- I needed a simple little function to take a string and convert extended ascii characters into html entities. I couldn't find a function for this so I whipped one up. <?php /* Convert Extended ASCII Characters to HTML Entities */ function ascii2entities($string){ for($i=128;$i<=255;$i++){ $entity = htmlentities(chr($i), ENT_QUOTES, 'cp1252'); $temp = substr($entity, 0, 1); $temp .= substr($entity, -1, 1); if ($temp != '&;'){ $string = str_replace(chr($i), '', $string); } else{ $string = str_replace(chr($i), $entity, $string); } } return $string; } echo ascii2entities("•"); ?>

« previous php.notes (#213304) next »