note 45691 deleted from function.chr by danbrown
| From: | danbrown@php.net | Date: | Wed, 15 Sep 2010 21:16:19 +0000 |
| Subject: | note 45691 deleted from function.chr by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-172604@lists.php.net to get a copy of this message | ||
Note Submitter: jon
----
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;
}
?>