note 75942 deleted from function.utf8-encode by cmb

From: Date: Sun, 22 Dec 2019 09:00:39 +0000
Subject: note 75942 deleted from function.utf8-encode by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-213575@lists.php.net to get a copy of this message
Note Submitter: luka8088 at gmail dot com ---- simple HTML to UTF-8 conversion: function html_to_utf8 ($data) { return preg_replace("/\\&\\#([0-9]{3,10})\\;/e", '_html_to_utf8("\\1")', $data); } function _html_to_utf8 ($data) { if ($data > 127) { $i = 5; while (($i--) > 0) { if ($data != ($a = $data % ($p = pow(64, $i)))) { $ret = chr(base_convert(str_pad(str_repeat(1, $i + 1), 8, "0"), 2, 10) + (($data - $a) / $p)); for ($i; $i > 0; $i--) $ret .= chr(128 + ((($data % pow(64, $i)) - ($data % ($p = pow(64, $i - 1)))) / $p)); break; } } } else $ret = "&#$data;"; return $ret; } Example: echo html_to_utf8("a b č ć ž こ に ち わ ()[]{}!#$?* < >"); Output: a b č ć ž こ に ち わ ()[]{}!#$?* < >

« previous php.notes (#213575) next »