php file_get_contents阿拉伯字符 [英] php file_get_contents Arabic Characters
问题描述
您好,我的PHP代码有问题: 我需要使用file_get_contents打开一个txt文件,该txt文件的目录包含阿拉伯字符 我的代码:
Hello I have a problem in my PHP code : I need to open a txt file using file_get_contents, the directory to the txt file contains arabic Characters my code:
$URLX = "C:/server files/BN/public_html" ;
$BookName = "الإضافةإلىمفاوضةمالكحسون" ;
$eachChapiter[$x] = "مالكمالكحسون" ;
$content = file_get_contents($URLX."/".$BookName."/".str_replace(' ', '', $eachChapiter[$x]).".txt");
错误输出:
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
推荐答案
感谢@Mike帮助我纠正了答案.因此,根据问题和OP的操作系统,看来您(OP)遇到的是
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.
正如该链接所讨论的,您可以使用以下代码来检测文件名编码
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");
请记住,此代码将在linux服务器上产生问题(再次在该链接上进行讨论).因此,如果您使用的是Linux生产环境,则可以应用此处建议的解决方案.
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.
这篇关于php file_get_contents阿拉伯字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!