diff options
author | Christian Schneider | 2022-12-12 16:55:47 +0100 |
---|---|---|
committer | Christian Schneider | 2022-12-12 16:55:47 +0100 |
commit | 55bd4e0052b830256ad1d1134bbe5c7231d1427b (patch) | |
tree | 49d4980bb599db87085b75c7780dc6138ad681db /it.class | |
parent | d6f07d7e1350c57e59192ba0047a8431fc59cdf3 (diff) | |
download | itools-55bd4e0052b830256ad1d1134bbe5c7231d1427b.tar.gz itools-55bd4e0052b830256ad1d1134bbe5c7231d1427b.tar.bz2 itools-55bd4e0052b830256ad1d1134bbe5c7231d1427b.zip |
Add and use it::utf8_decode and it::utf8_encode for easier migration to PHP 8.2
Diffstat (limited to 'it.class')
-rw-r--r-- | it.class | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -587,9 +587,9 @@ static function any2utf8($value, $errprefix = "") else if (is_string($value)) { if (grapheme_strlen($value) === null) - list($value, $error) = array(utf8_encode($value), utf8_encode("incorrect utf8-encoding. input=$value")); + list($value, $error) = array(it::utf8_encode($value), it::utf8_encode("incorrect utf8-encoding. input=$value")); if (preg_match('/\xc3[\x82\x83]\xc2[\x82\x83\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(it::any2utf8(preg_replace_callback('/\xc3[\x82\x83]\xc2[\x82\x83\xbc\xa9\xa4\xb6\xa8\xa2\xa0\xb4\xaa\xa7\x84\xab\xae\x9c\xaf\x96\xb2\xbb\xb9\x9f]/', function($m) {return utf8_decode($m[0]);}, $value)), $errprefix ? "double utf8-encoding. input=$value" : ""); + list($value, $error) = array(it::any2utf8(preg_replace_callback('/\xc3[\x82\x83]\xc2[\x82\x83\xbc\xa9\xa4\xb6\xa8\xa2\xa0\xb4\xaa\xa7\x84\xab\xae\x9c\xaf\x96\xb2\xbb\xb9\x9f]/', function($m) {return it::utf8_decode($m[0]);}, $value)), $errprefix ? "double utf8-encoding. input=$value" : ""); if (preg_match('/\xef\xb7[\x90-\xaf]|\xef\xbf[\xbe\xbf]/', $value)) list($value, $error) = array(preg_replace('/\xef\xb7[\x90-\xaf]|\xef\xbf[\xbe\xbf]/', " ", $value), "forbidden utf-8 character. input=$value"); $value = preg_replace('/\xc2\xad/', '', $value); # Kill invisible soft hyphens @@ -1369,4 +1369,14 @@ static function request_body() return it::any2utf8(it::file_get_contents('php://input')); } +static function utf8_decode($utf8) +{ + return UConverter::transcode($utf8, 'ISO-8859-1', 'UTF8', ['to_subst' => '?']); +} + +static function utf8_encode($latin1) +{ + return UConverter::transcode($latin1, 'UTF8', 'ISO-8859-1'); +} + } |