Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 文件\u获取\u内容-URL中的特殊字符-特殊大小写_Php_Utf 8_Character Encoding_File Get Contents - Fatal编程技术网

Php 文件\u获取\u内容-URL中的特殊字符-特殊大小写

Php 文件\u获取\u内容-URL中的特殊字符-特殊大小写,php,utf-8,character-encoding,file-get-contents,Php,Utf 8,Character Encoding,File Get Contents,在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_content

在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上按预期工作

我尝试了以下解决方案,但没有效果:

一,

二,

三,

四,

在这些问题中可以找到:

更新:
如您所见,在我的示例中实际返回了一个页面,但它不是预期的页面,即您在浏览器中键入url时得到的页面

需要对unicode字符进行百分比编码。这是我知道的一种方法

$url2 = "https://se.timeedit.net/web/liu/db1/schema/s/s.html?tab=3&object=" . urlencode('CM_949A11_1534_1603_DAG_DST_50_ÖVRIGT_1_1') . "&type=subgroup&startdate=20150101&enddate=20300501";
echo "encoded: " . $url2;
print file_get_contents($url2);

URL不能包含“Ö”从这个基本前提开始。任何不在狭义定义的ASCII子集内的字符都必须进行URL编码,以在URL中表示。正确的方法是
urlencode
rawurlencode
(取决于服务器期望的格式)URL的单个段,而不是整个URL

例如:


您仍然需要对字符串使用正确的编码Ö将URL编码为
%D6
,而UTF-8中的代码>Ö将编码为
%C3%96
。哪一个是正确的取决于服务器的期望

您可能想快速查看以下链接:@HomelessPerson正如我在问题中所写的那样,我已经看到了这个问题,您能指出我案例的相关部分吗?
print mb_convert_encoding($url, 'HTML-ENTITIES', "UTF-8");
$url = urlencode($url);
print file_get_contents($url);
$content = file_get_contents($url);
print mb_convert_encoding($content, 'UTF-8', mb_detect_encoding($content, 'UTF-8, ISO-8859-1', true));
$url2 = "https://se.timeedit.net/web/liu/db1/schema/s/s.html?tab=3&object=" . urlencode('CM_949A11_1534_1603_DAG_DST_50_ÖVRIGT_1_1') . "&type=subgroup&startdate=20150101&enddate=20300501";
echo "encoded: " . $url2;
print file_get_contents($url2);
$url = sprintf('https://se.timeedit.net/web/liu/db1/schema/s/s.html?tab=3&object=%s&type=subgroup&startdate=20150101&enddate=20300501',
               rawurlencode('CM_949A11_1534_1603_DAG_DST_50_ÖVRIGT_1_1'));