2014-12-04 45 views
0
<?php 
require_once 'test中文.php'; 

C:\ WNMP \ PHP \的php.exe C:\ WNMP \ HTML \臨河\ test0.phpPHP的包括中國名

PHP Warning: require_once(test中文.php): failed to open stream: No such file or directory in C:\Wnmp\html\linhe\test0.php on line 4

PHP堆棧跟蹤:

PHP 1. {main}() C:\Wnmp\html\linhe\test0.php:0 

PHP Fatal error: require_once(): Failed opening required 'test中文.php' (include_path='.;C:\Wnmp\php\pear') in C:\Wnmp\html\linhe\test0.php on line 4

PHP堆棧跟蹤:

PHP 1. {main}() C:\Wnmp\html\linhe\test0.php:0 

處理完成退出代碼255

我知道的東西: test中文.php是一個空白文件;
與梨沒有關係。
包括英文文件名是好的!

謝謝!

回答

1

處理非ASCII文件名在PHP中非常棘手,因爲它完全委託給底層文件系統。文件系統本身如何存儲取決於您的系統,並且可能在不同系統之間存在很大差異。簡短的答案是:您需要匹配底層文件系統的編碼。如果您的PHP代碼採用UTF-8編碼文件,因此字符串"test中文.php"採用UTF-8編碼,但文件系統實際上存儲了編碼的文件名,例如GB18030,則文件名不匹配。你不得不做這樣的事情:再次

$file = 'test中文.php'; 
$file = iconv('UTF-8', 'GB18030', $file); 
require_once $file; 

但是,因爲準確的編碼使用可以在兩個系統和/或編碼可能比簡單的iconv通話更加複雜之間的差異,這是一個巨大的痛苦在脖子上處理這件事。長的答案要複雜得多,通常歸結爲:只要堅持ASCII文件名。

+0

是的!我試過$ s ='test中文.php'; $ s = mb_convert_encoding($ s,'GB2312'); require_once $ s; – 2014-12-04 05:54:32

+0

嗨,請問另一個問題,我怎麼知道os文件系統的字符集!謝謝 – 2014-12-04 09:15:15

+0

功能編碼($ file_name){ if('WINNT'== PHP_OS) return mb_convert_encoding($ file_name,'GB18030'); return $ file_name; } – 2014-12-04 09:39:01