{% else-1 %}
Удаление невалидных символов XML (чаще всего для парсеров API)

                        
<?php 
function stripInvalidXml($value)
{
$ret = "";
$current;
if (empty($value))
{
return $ret;
}

$length = strlen($value);
for ($i=0; $i < $length; $i++)
{
$current = ord($value{$i});
if (($current == 0x9) ||
($current == 0xA) ||
($current == 0xD) ||
(($current >= 0x20) && ($current <= 0xD7FF)) ||
(($current >= 0xE000) && ($current <= 0xFFFD)) ||
(($current >= 0x10000) && ($current <= 0x10FFFF)))
{
$ret .= chr($current);
}
else
{
$ret .= " ";
}
}
return $ret;
}
4 62 0
Без комментариев...