diff options
author | Urban Müller | 2010-02-18 18:38:08 +0000 |
---|---|---|
committer | Urban Müller | 2010-02-18 18:38:08 +0000 |
commit | 55026001ce09c4120a99a6142fa56dc6c7556da9 (patch) | |
tree | b4bff0c3adb73d63f43faa6b2b0891fe52c87319 | |
parent | 4a032b0a5ee90d3ec30b9be70cd89a15fc3f0b70 (diff) | |
download | itools-55026001ce09c4120a99a6142fa56dc6c7556da9.tar.gz itools-55026001ce09c4120a99a6142fa56dc6c7556da9.tar.bz2 itools-55026001ce09c4120a99a6142fa56dc6c7556da9.zip |
extract latinize() for search::utf2latin
-rw-r--r-- | it_html.class | 13 |
1 files 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; } |