Voting

: one plus three?
(Example: nine)

The Note You're Voting On

phil at lavin dot me dot uk
15 years ago
The following will make a string completely safe for XML:

<?php
function philsXMLClean($strin) {
$strout = null;

for (
$i = 0; $i < strlen($strin); $i++) {
$ord = ord($strin[$i]);

if ((
$ord > 0 && $ord < 32) || ($ord >= 127)) {
$strout .= "&amp;#{$ord};";
}
else {
switch (
$strin[$i]) {
case
'<':
$strout .= '&lt;';
break;
case
'>':
$strout .= '&gt;';
break;
case
'&':
$strout .= '&amp;';
break;
case
'"':
$strout .= '&quot;';
break;
default:
$strout .= $strin[$i];
}
}
}

return
$strout;
}
?>

<< Back to user notes page

To Top