为什么我得到这个错误:
无法打开流:HTTP 请求失败!HTTP/1.1 404 未找到
法典:
$Name = 'Teàst';
$result = file_get_contents('http://example.com/name/' . $Name . );
但是当我尝试echo $result;
时,我得到了链接并且它的工作正常。当我尝试$Name = 'Teast';
(没有"à"符号(时,它的工作正常。所以问题是带有符号的名称(é è à ...(。请问如何解决?
使用
htmlspecialchars((
$Name = 'Teàst';
$Name =htmlspecialchars($Name);
$result = file_get_contents('http://example.com/name/' .$Name);
这段代码对我有用:
<?php
$Name = 'Teàst';
$result = file_get_contents('http://example.com/name/' . $Name );
echo $result
?>
这段代码有效:
<?php
$Name = 'Teàst';
$Name = htmlspecialchars($Name);
$result = file_get_contents('http://localhost/temp/' . $Name);
echo $result
?>
使用 htmlspecialchars 方法,
$Name = 'Teàst';
$result = file_get_contents('http://example.com/name/' . htmlspecialchars($Name));