Home >Backend Development >PHP Tutorial >PHP 关于fopen读取带有特殊字符文件名问题

PHP 关于fopen读取带有特殊字符文件名问题

WBOY
WBOYOriginal
2016-06-06 20:12:121623browse

例如我的文件名是:上海“1+1”峰会的 [报告及评估].pdf
求一个解决办法;

回复内容:

例如我的文件名是:上海“1+1”峰会的 [报告及评估].pdf
求一个解决办法;

<code><?php $string = '上海“1+1”峰会的 [报告及评估].txt';
$string = iconv('UTF-8','GB2312',$string);

$file = fopen($string,'r');
echo fgets($file);
</code></code>

我写了一个demo,其实中间只需要进行一次字符串转化,转化为gb2312就可以了

<code>$string = '上海“1+1”峰会的 [报告及评估].pdf';
$string = iconv('UTF-8','GB2312',$string);
</code>

修改(GB2312改为了GBK,好像就解决了):

<code>$str = './粤食药监办科﹝2016﹞115号 关于印发推进“互联网+食品药品监管”的实施方案的通知.txt';

$str = iconv('UTF-8','GBK',$str);
$file = fopen($str,'r');
echo fgets($file);
</code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn