Last active
December 12, 2015 12:28
-
-
Save MartinSadovy/4771705 to your computer and use it in GitHub Desktop.
Windows uses the local character encoding (cp125*) for file and directory name.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function utf8ToLocalEncoding($s) { | |
if (substr(PHP_OS, 0, 3) === 'WIN') { | |
$tmp = explode(".", setlocale(LC_CTYPE, 0)); | |
if (isset($tmp[1]) && is_numeric($tmp[1])) | |
$s = @iconv("UTF-8", "cp" . $tmp[1] . "//TRANSLIT", $s); | |
} | |
return $s; | |
} | |
function localEncodingToUtf8($s) { | |
if (substr(PHP_OS, 0, 3) === 'WIN') { | |
$tmp = explode(".", setlocale(LC_CTYPE, 0)); | |
if (isset($tmp[1]) && is_numeric($tmp[1])) | |
$s = @iconv("cp" . $tmp[1] . "//TRANSLIT", "UTF-8", $s); | |
} | |
return $s; | |
} | |
$original = "ěščřžýáíé"; | |
$a = utf8toLocalEncoding($original); | |
$b = localEncodingToUtf8($a); | |
var_dump($original, $a, $b, $original === $b); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment