3v4l.org

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