From 55026001ce09c4120a99a6142fa56dc6c7556da9 Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Thu, 18 Feb 2010 18:38:08 +0000 Subject: extract latinize() for search::utf2latin --- it_html.class | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/it_html.class b/it_html.class index 47444a6..e628a23 100644 --- a/it_html.class +++ b/it_html.class @@ -415,6 +415,13 @@ function sanitize($html) return $result; } +/** + * Replace or remove all illegal characters from a latin-1 string + */ +function latinize($string) +{ + return preg_replace('/[\x00-\x08\x0b-\x0c\x0e-\x1f\x80-\x9f]/', ' ', strtr($string, array("\x80" => "EUR", "\x82" => "'", "\x84" => "\"", "\x85" => "...", "\x8a" => "S", "\x8c" => "OE", "\x8e" => "Z", "\x91" => "'", "\x92" => "'", "\x93" => "\"", "\x94" => "\"", "\x96" => "-", "\x97" => "-", "\x9a" => "s", "\x9e" => "z"))); +} /** * Shortcut: return htmlspecialchars($string) and encode forbidden characters 80-9f if latin1 is output @@ -423,10 +430,10 @@ function sanitize($html) */ function Q($string) { - if ($GLOBALS['it_html']->p['charset'] == "iso-8859-1") - $string = preg_replace('/[\x00-\x08\x0b-\x0c\x0e-\x1f\x80-\x9f]/', ' ', strtr($string, array("\x80" => "EUR", "\x82" => "'", "\x84" => "\"", "\x85" => "...", "\x8a" => "S", "\x8c" => "OE", "\x8e" => "Z", "\x91" => "'", "\x92" => "'", "\x93" => "\"", "\x94" => "\"", "\x96" => "-", "\x97" => "-", "\x9a" => "s", "\x9e" => "z"))); + if (preg_match('/[<>&"\x00-\x08\x0b-\x0c\x0e-\x1f\x80-\x9f]/', $string)) + $string = htmlspecialchars($GLOBALS['it_html']->p['charset'] == "iso-8859-1" ? it_html::latinize($string) : $string); - return htmlspecialchars($string); + return $string; } -- cgit v1.2.3