diff options
Diffstat (limited to 'it.class')
-rw-r--r-- | it.class | 14 |
1 files changed, 10 insertions, 4 deletions
@@ -406,16 +406,22 @@ static function grep($pattern, $array, $p = array()) } /** - * Convert string to utf8 if it was not already utf-8 before + * Convert string to utf8 if it was not already utf-8 before. Also handles double encoding * @param $value String to convert + * @param $errmsg Error message to output if anything needed to be done * @return Same string in utf-8 encoding */ -function any2utf8($value) +function any2utf8($value, $errmsg = "") { if (grapheme_strlen($value) === null) - $value = utf8_encode($value); + list($value, $error) = array(utf8_encode($value), utf8_encode("$errmsg: incorrect utf8-encoding. input=" . trim($value))); + if (preg_match('/\xc3\x83\xc2([\xbc\xa9\xa4\xb6\xa8\xa2\xa0\xb4\xaa\xa7\x84\xab\xae\x9c\xaf\x96\xb2\xbb\xb9\x9f])/', $value)) + list($value, $error) = array(preg_replace('/\xc3\x83\xc2([\xbc\xa9\xa4\xb6\xa8\xa2\xa0\xb4\xaa\xa7\x84\xab\xae\x9c\xaf\x96\xb2\xbb\xb9\x9f])/', "\xc3\$1", $value), utf8_encode("$errmsg: double utf8-encoding. input=" . trim($value))); - return preg_replace('/\xc3\x83\xc2([\xbc\xa9\xa4\xb6\xa8\xa2\xa0\xb4\xaa\xa7\x84\xab\xae\x9c\xaf\x96\xb2\xbb\xb9\x9f])/', "\xc3\$1", $value); # fix most common double encodings, UTF8SAFE + if ($error && $errmsg) + it::error(array('title' => $error, 'skipfiles' => "it_html")); + + return $value; } /** |