【发布时间】:2015-10-21 14:42:20
【问题描述】:
在 URL 包含“Ö”字符的这种特殊情况下,我没有让 file_get_contents() 返回页面。
$url = "https://se.timeedit.net/web/liu/db1/schema/s/s.html?tab=3&object=CM_949A11_1534_1603_DAG_DST_50_ÖVRIGT_1_1&type=subgroup&startdate=20150101&enddate=20300501"
print file_get_contents($url);
如何使 file_get_contents() 在此 url 上按预期工作?
我尝试了以下解决方案,但没有奏效:
1.
print rawurlencode(utf8_encode($url));
2.
print mb_convert_encoding($url, 'HTML-ENTITIES', "UTF-8");
3.
$url = urlencode($url);
print file_get_contents($url);
4.
$content = file_get_contents($url);
print mb_convert_encoding($content, 'UTF-8', mb_detect_encoding($content, 'UTF-8, ISO-8859-1', true));
在这些问题中找到:
file_get_contents - special characters in URL
PHP get url with special characters without urlencode:ing them!
file_get_contents() Breaks Up UTF-8 Characters
更新: 如您所见,在我的示例中实际上返回了一个页面,但它不是预期的页面,是您在浏览器中键入 url 时得到的页面。
【问题讨论】:
-
您可能想快速浏览以下链接:stackoverflow.com/questions/2236668/…
-
@HomelessPerson 正如我在问题中所写的,我已经看到了这个问题,您能否指出我的案例的相关部分?
标签: php utf-8 character-encoding file-get-contents