Posted by lkrubner on 10/11/05 01:09
Whenever users write a post in Microsoft Word and then post it to
their weblogs using my PHP software, their RSS feed ends up being
corrupted with garbage characters which violate the well-formedness of
their XML and therefore cause their newsreaders to die.
This function will probably make the character strings completely safe
for XML? I don't care about having garbage characters in the RSS feed,
I just want the RSS feed to show up, without causing anyone's newsfeed
reader to die.
function command($string=false) {
$howMany = strlen($string);
$newString = "";
for ($i=0; $i < $howMany; $i++) {
$char = $string[$i];
$asciiNum = ord($char);
if ($asciiNum > 32 && $asciiNum < 128) {
$newString .= $char;
} else {
$newString .= "'";
}
}
return $newString;
}
[Back to original message]
|