3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function utf8ToLocalEncoding($s) { if (substr(PHP_OS, 0, 3) === 'WIN' || true) { $tmp = explode(".", setlocale(LC_CTYPE, 0)); if (isset($tmp[1]) && is_int($tmp[1])) $s = @iconv("UTF-8", "cp" . $tmp[1] . "//TRANSLIT", $s); } return $s; } function localEncodingToUtf8($s) { if (substr(PHP_OS, 0, 3) === 'WIN' || true) { $tmp = explode(".", setlocale(LC_CTYPE, 0)); if (isset($tmp[1]) && is_int($tmp[1])) $s = @iconv("cp" . $tmp[1] . "//TRANSLIT", "UTF-8", $s); } return $s; } $original = "šířéč"; $a = utf8toLocalEncoding($original); $b = localEncodingToUtf8($a); var_dump(setlocale(LC_CTYPE, 0)); var_dump($original, $a, $b, $original === $b);
Output for 4.3.0 - 7.1.0
string(1) "C" string(10) "šířéč" string(10) "šířéč" string(10) "šířéč" bool(true)