如何使用php file-get-contents函数打开具有阿拉伯文本的url [英] How to open url having Arabic text using php file-get-contents function

查看:56
本文介绍了如何使用php file-get-contents函数打开具有阿拉伯文本的url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to get html from a URL having some Arabic like

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

使用php. 我尝试过

using php. I tried with

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

仅供参考,不存在.

推荐答案

URLs 不能包含非ASCII字符.

在看起来确实可行的地方,实际上是浏览器在后台将您的字符无声转换为URL转义的字符.

Where it seems that they do, it's in fact the browser silently converting your characters into URLescaped ones in the background.

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

When you paste this URL into your browser:

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().

PHP doesn't have this ability to silently convert characters; you'll have to do it manually. To do that, run PHP's urlencode() over the URL before making the call.

这篇关于如何使用php file-get-contents函数打开具有阿拉伯文本的url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆