function google_base_xml_sanitizer($str, $cdata = false) {
$str = str_replace(array("\t" , "\n", "\r"), ' ', $str);
$str = eregi_replace("[^[:alnum:][:space:].,!()'-_/+=?äÂÄöÖüÜß]", "", $str);
$str = htmlentities(html_entity_decode($str));
$str = utf8_encode(str_replace(array("®", "©", "™"), array('(r)', '(c)', '(tm)'), $str));
$str = $this->real_strip_tags($str, array('br', 'p'), false);
$out = "";
$length = strlen($str);
for ($i = 0; $i < $length; $i++) {
$current = ord($str{$i});
if ( (($current == 0x9) || ($current == 0xA) || ($current == 0xD) || (($current >= 0x20) && ($current <= 0xD7FF)) || (($current >= 0xE000) && ($current <= 0xFFFD)) || (($current >= 0x10000) && ($current <= 0x10FFFF))) && ($current > 10) ) {
$out .= chr($current);
} else {
$out .= " ";
}
}
$str = trim($out);
$str = str_replace(array("<", ">"), array("<", ">"), $str);
if ($cdata) {
$str = '<![CDATA[' . $str . ']]>';
}
return $str;
}
function real_strip_tags($i_html, $i_allowedtags = array(), $i_trimtext = FALSE) {
if (!is_array($i_allowedtags))
$i_allowedtags = !empty($i_allowedtags) ? array($i_allowedtags) : array();
$tags = implode('|', $i_allowedtags);
if (empty($tags))
$tags = '[a-z]+';
preg_match_all('@</?\s*(' . $tags . ')(\s+[a-z_]+=(\'[^\']+\'|"[^"]+"))*\s*/?>@i', $i_html, $matches);
$full_tags = $matches[0];
$tag_names = $matches[1];
foreach ($full_tags as $i => $full_tag) {
if (!in_array($tag_names[$i], $i_allowedtags))
if ($i_trimtext)
unset($full_tags[$i]);
else
$i_html = str_replace($full_tag, '', $i_html);
}
return $i_trimtext ? implode('', $full_tags) : $i_html;
}
Bookmarks