note 30732 added to function.chr

From: Date: Thu, 27 Mar 2003 00:12:34 +0000
Subject: note 30732 added to function.chr
Groups: php.notes 
Request: Send a blank email to php-notes+get-45872@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. 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://www.php.net/manual/en/function.chr.php http://master.php.net/manage/user-notes.php?action=edit+30732 http://master.php.net/manage/user-notes.php?action=delete+30732 http://master.php.net/manage/user-notes.php?action=reject+30732

« previous php.notes (#45872) next »