最近在windows的php环境突然发现windows的php的文件函数文件名都是使用的GBK编码没有使用utf-8编码。于是需要手动转换一下编码。当然了linux系统都是使用的utf-8编码就没有这些问题啦。
我写了一些常用的函数的包装,供大家方便使用
$Server_System; if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { $Server_System = 'windows';//filename will be changed into utf-8 in windows } else { $Server_System = 'linux'; } function my_file_exists($path) { global $Server_System; if($Server_System == 'windows') { $path = iconv('utf-8','gbk',$path); } return file_exists($path); } function my_file_get_contents($path) { global $Server_System; if($Server_System == 'windows') { $path = iconv('utf-8','gbk',$path); } return file_get_contents($path); } function my_filemtime($path) { global $Server_System; if($Server_System == 'windows') { $path = iconv('utf-8','gbk',$path); } return filemtime($path); } function my_file_put_contents($path,$data) { global $Server_System; if($Server_System == 'windows') { $path = iconv('utf-8','gbk',$path); } return file_put_contents($path,$data); } function my_is_dir($path) { global $Server_System; if($Server_System == 'windows') { $path = iconv('utf-8','gbk',$path); } return is_dir($path); } function my_md5_file($path) { global $Server_System; if($Server_System == 'windows') { $path = iconv('utf-8','gbk',$path); } return md5_file($path); } function my_sha1_file($path) { global $Server_System; if($Server_System == 'windows') { $path = iconv('utf-8','gbk',$path); } return sha1_file($path); }
通过某奇怪的方式找到了这里,正好发现了需要的东西,感谢分享O(∩_∩)O~