note 45691 added to function.chr

From: Date: Wed, 15 Sep 2004 11:11:11 +0000
Subject: note 45691 added to function.chr
Groups: php.notes 
Request: Send a blank email to php-notes+get-76728@lists.php.net to get a copy of this message
in response to jcokos's function for catching non-Ascii values when converting to entitites for XML. I have found it better to use htmlspecialchars rather than htmlentities because htmlentities does convert some non-Ascii characters to entitities, for example the copyright symbol. To be fully compliant with XML, the numeric entity should be used, rather than the symbolic version used in htmlentities. <?php function strictify ( $string ) { $fixed = htmlspecialchars( $string, ENT_QUOTES ); $trans_array = array(); for ($i=127; $i<255; $i++) { $trans_array[chr($i)] = "&#" . $i . ";"; } $really_fixed = strtr($fixed, $trans_array); return $really_fixed; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.chr.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+45691 Delete -- http://master.php.net/manage/user-notes.php?action=delete+45691&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+45691&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#76728) next »