diff options
-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; } |