php file_get_content阿拉伯字符
Hello I have a problem in my PHP code : I need to open a txt file using file_get_content, the directory to the txt file contains arabic Characters my code:
您好我的PHP代码有问题:我需要使用file_get_content打开一个txt文件,txt文件的目录包含阿拉伯语字符我的代码:
$URLX = "C:/server files/BN/public_html" ;
$BookName = "الإضافةإلىمفاوضةمالكحسون" ;
$eachChapiter[$x] = "مالكمالكحسون" ;
$content = file_get_contents($URLX."/".$BookName."/".str_replace(' ', '', $eachChapiter[$x]).".txt");
the error output :
错误输出:
WARNING: FILE_GET_CONTENTS(C:/SERVER FILES/BN/PUBLIC_HTML/الإضافةإلىمفاوضةمالكحسون/مالكمالكحسون.TXT): FAILED TO OPEN STREAM: NO SUCH FILE OR DIRECTORY IN C:\XAMPP\HTDOCS\LIBRARY\SEARCH\SEARCH.PHP ON LINE 30
NOTICE: UNDEFINED OFFSET: 1 IN C:\XAMPP\HTDOCS\LIBRARY\SEARCH\SEARCH.PHP ON LINE 38
1 个解决方案
#1
1
Thanks @Mike for helping me correct the answer. So As per the question and OP's OS it seems that you(OP) are encountering a variant of this error.
感谢@Mike帮我纠正了答案。所以根据问题和OP的操作系统,你(OP)似乎遇到了这个错误的变种。
And as discussed on that link, you can use the following code to detect the file name encoding
如该链接所述,您可以使用以下代码来检测文件名编码
...
$final_url = $URLX."/".$BookName."/".str_replace(' ', '', $eachChapiter[$x]);
mb_detect_encoding($final_url, 'UTF-8', true)) ? utf8_decode($final_url) : $final_url;
$content = file_get_contents($final_url).".txt");
Remember that this code will create problems(again discussed on that link) on a linux server. So if you are using Linux production environment then you can apply the solution suggested there.
请记住,此代码将在Linux服务器上产生问题(在该链接上再次讨论)。因此,如果您使用的是Linux生产环境,则可以应用此处建议的解决方案。
更多相关文章
- php二维码/26行代码制作php二维码phpqrcode加grafika水印
- php分页代码的问题,显示了两个当前页码,求大神解答
- PHP开发微信支付代码及支付通知处理
- 几个有用的php字符串过滤,转换函数代码
- 在Web Page中包含PHP代码
- php mail函数一段好的代码
- 用于上传多个文件的PHP代码
- (phpQuery)对网站产品信息采集代码的优化
- 韩顺平_php从入门到精通_视频教程_学习笔记_源代码图解_PPT文档