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生产环境,则可以应用此处建议的解决方案。

更多相关文章

  1. php二维码/26行代码制作php二维码phpqrcode加grafika水印
  2. php分页代码的问题,显示了两个当前页码,求大神解答
  3. PHP开发微信支付代码及支付通知处理
  4. 几个有用的php字符串过滤,转换函数代码
  5. 在Web Page中包含PHP代码
  6. php mail函数一段好的代码
  7. 用于上传多个文件的PHP代码
  8. (phpQuery)对网站产品信息采集代码的优化
  9. 韩顺平_php从入门到精通_视频教程_学习笔记_源代码图解_PPT文档

随机推荐

  1. 中文分词原理及常用Python中文分词库介绍
  2. 轻松获得海量稳定代理!ADSL拨号代理的搭建
  3. 183条地铁线路,3034个地铁站,发现中国地铁
  4. App爬虫神器mitmproxy和mitmdump的使用
  5. Attention原理及TensorFlow AttentionWra
  6. Unity平台 | 快速集成华为AGC AppLinking
  7. 妈妈再也不用担心爬虫被封号了!手把手教你
  8. Python数据科学:神经网络
  9. 火箭五年四遇勇士,终究还是败了。
  10. python 接口自动化测试-----常见面试题汇