|
This is a little bit more efficient version of regins entity converter. ;-)
<?php
function xmlEntities($string)
{
$return = '';
for($i = 0; $i < strlen($string); $i++)
{
$ascii = ord($string{$i});
if(($ascii >= 48 && $ascii <= 57) ||
($ascii >= 65 && $ascii <= 90) ||
($ascii >= 97 && $ascii <= 122))
{
$return .= $string{$i};
}
else
{
$return .= '&#'.$ascii.';';
}
}
return $return;
}
?>
Sign up to add your own comment here!
|
|