解決file_get_contents遇到中文文件名無法打開問題
比如:受訪頁面_20151202-20151202.csv
file_get_contents(受訪頁面_20151202-20151202.csv)就會報錯
[function.file-get-contents]: failed to open stream: No such file or directory
改成不用包含中文的文件名路徑就可以。
原因:
編碼問題,Windows中是使用gbk中文編碼的,而PHP文件一般都是用utf-8格式保存的了。中文地址獲取之前做一次iconv('utf-8', 'gbk', $path)就沒有問題了。
- <?php
- $path='/baidu/受訪頁面_20151203-20151203.csv';
- $path=iconv('utf-8', 'gbk', $path);
- $content= file_get_contents($path);
- echo $content;
- ?>
新聞熱點
疑難解答