如何使用php文件获取内容函数打开具有阿拉伯语文本的url


How to open url having Arabic text using php file-get-contents function

我想从具有类似阿拉伯语的URL中获取html

http://www.example.com/2013/07/31/الاختبار.html

使用php。我试过

file_get_html("http://www.example.com/2013/07/31/الاختبار.html")

但它给出了以下错误

Warning: file_get_contents(http://www.example.com/2013/07/31/الاختبار.html) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found in filename.php

请帮忙。

http://www.example.com/2013/07/31/الاختبار.html

仅供参考,不存在。

URL不能包含非ASCII字符。

事实上,浏览器在后台无声地将你的角色转换为URLScaped角色。

当您将此URL粘贴到浏览器中时:

http://www.example.com/2013/07/31/الاختبار.html

在现实中会是这样的:

http://www.example.com/2013/07/31/%D8%A7%D9%84%D8%A7%D8%AE%D8%AA%D8%A8%D8%A7%D8%B1.html

PHP没有这种静默转换字符的能力;你必须手动操作。为此,在进行调用之前,在URL上运行PHP的urlencode()