note 30732 modified in function.chr by vrana
| From: | vrana@php.net | Date: | Tue, 17 Aug 2004 14:54:45 +0000 |
| Subject: | note 30732 modified in function.chr by vrana | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-79867@lists.php.net to get a copy of this message | ||
A quick function that I use to make strings "XML" compliant, changing every special
character into their #$... equivalent.
htmlentities doesn't get all of the chars above 127, so the second part of this (which I stole
from one of the comments above) finishes the process, returning a nice, xml happy string.
<?php
function strictify ( $string ) {
$fixed = htmlentities( $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;
}
?>
HTH
--was--
A quick function that I use to make strings "XML" compliant, changing every special
character into their #$... equivalent.
htmlentities doesn't get all of the chars above 127, so the second part of this (which I stole
from one of the comments above) finishes the process, returning a nice, xml happy string.
function strictify ( $string ) {
$fixed = htmlentities( $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;
}
HTH
http://php.net/manual/en/function.chr.php