diff options
author | Urban Müller | 2012-05-15 13:39:44 +0000 |
---|---|---|
committer | Urban Müller | 2012-05-15 13:39:44 +0000 |
commit | 14f9b743304695c729f4e5e7a5a36fbd4547de41 (patch) | |
tree | 573b0e75d098dc74ff40c882cb82378b69ed2971 /it.class | |
parent | e2974f041d43b0ce99488027dd38187d606dd552 (diff) | |
download | itools-14f9b743304695c729f4e5e7a5a36fbd4547de41.tar.gz itools-14f9b743304695c729f4e5e7a5a36fbd4547de41.tar.bz2 itools-14f9b743304695c729f4e5e7a5a36fbd4547de41.zip |
support arrays in any2utf8
Diffstat (limited to 'it.class')
-rw-r--r-- | it.class | 24 |
1 files changed, 16 insertions, 8 deletions
@@ -410,19 +410,27 @@ static function grep($pattern, $array, $p = array()) /** * Convert string to utf8 if it was not already utf-8 before. Also handles double encoding - * @param $value String to convert + * @param $value String or array to convert * @param $errmsg Error message to output if anything needed to be done * @return Same string in utf-8 encoding */ function any2utf8($value, $errmsg = "") { - if (grapheme_strlen($value) === null) - 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))); - - if ($error && $errmsg) - it::error(array('title' => $error, 'skipfiles' => "it_html")); + if (is_array($value)) + { + foreach ($value as $idx => $v) + if (is_string($v) || is_array($v)) + $value[$idx] = self::any2utf8($v, $errmsg); + } + else + { + if (grapheme_strlen($value) === null) + 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))); + if ($error && $errmsg) + it::error(array('title' => $error, 'skipfiles' => "it_html")); + } return $value; } |