遭遇windows上PHP 不能打开GBK编码文件名的问题

我在 目录下建了一个文件名为 謀定三國-i8ujlw.json

 

然后在其下建了一个demo.php文件,内容如下:

<?php
function recursion_glob($dir, $pattern)
{
    $dir = rtrim($dir, '/\\') . DIRECTORY_SEPARATOR;
    $files = array();

    $dh = opendir($dir);
    if (!$dh) return $files;

    $items = (array)glob($dir . $pattern);
    foreach ($items as $item)
    {
        if (is_file($item)) $files[] = $item;
    }

    while (($file = readdir($dh)))
    {
        if ($file == '.' || $file == '..') continue;

        $path = $dir . $file;
        if (is_dir($path))
        {
            $files = array_merge($files, recursion_glob($path, $pattern));
        }
    }
    closedir($dh);
    return $files;
}

$files = recursion_glob(__DIR__, '*.json'); 
if ( !empty($files) )
{
	foreach ( $files as $file )
	{
		if(!is_readable($file))
		{
			print "cannot find: ($file)\n";
		}
        else
        {
            print "load file: ($file)\n";   
        }
	}
}

?>			

 

 遭遇windows上PHP 不能打开GBK编码文件名的问题

打开windows cmd控制台,输入 php demo.php

C:\tmp\md>php demo.php
load file: (C:\tmp\md\谋定三国-i8ujlw.json)
cannot find: (C:\tmp\md\謀定三國-i8ujlw.json)

 

打印出来的结果是不是很坑爹

 

 

PHP Version 5.5.1

 

System Windows NT WIN-290JCDFNA40 6.2 build 9200 (Windows 8 Business Edition) i586
Build Date Jul 18 2013 10:37:55
Compiler MSVC11 (Visual C++ 2012)
Architecture x86
Configure Command cscript /nologo configure.js "--enable-snapshot-build" "--enable-debug-pack" "--disable-zts" "--disable-isapi" "--disable-nsapi" "--without-mssql" "--without-pdo-mssql" "--without-pi3web" "--with-pdo-oci=C:\php-sdk\oracle\instantclient10\sdk,shared" "--with-oci8=C:\php-sdk\oracle\instantclient10\sdk,shared" "--with-oci8-11g=C:\php-sdk\oracle\instantclient11\sdk,shared" "--with-enchant=shared" "--enable-object-out-dir=../obj/" "--enable-com-dotnet=shared" "--with-mcrypt=static" "--disable-static-analyze" "--with-pgo"
Server API CGI/FastCGI
Virtual Directory Support disabled
Configuration File (php.ini) Path C:\Windows
Loaded Configuration File C:\soft\upupw\PHP5\php.ini
Scan this dir for additional .ini files (none)
Additional .ini files parsed (none)
PHP API 20121113
PHP Extension 20121212
Zend Extension 220121212
Zend Extension Build API220121212,NTS,VC11
PHP Extension Build API20121212,NTS,VC11
Debug Build no
Thread Safety disabled
Zend Signal Handling disabled
Zend Memory Manager enabled
Zend Multibyte Support provided by mbstring
IPv6 Support enabled
DTrace Support disabled
Registered PHP Streams php, file, glob, data, http, ftp, zip, compress.zlib, compress.bzip2, https, ftps, phar
Registered Stream Socket Transports tcp, udp, ssl, sslv3, sslv2, tls
Registered Stream Filters convert.iconv.*, mcrypt.*, mdecrypt.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, dechunk, zlib.*, bzip2.*

 

Zend logoThis program makes use of the Zend Scripting Language Engine:
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
    with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans

你可能感兴趣的:(windows)