无法打开流:HTTP请求失败错误,名称带符号

时间:2015-03-31 07:44:09

标签: php string echo

为什么我收到此错误:

  

无法打开流:HTTP请求失败!找不到HTTP / 1.1 404

代码:

$Name = 'Teàst';
$result = file_get_contents('http://example.com/name/' . $Name . );

但是当我尝试echo $result;时,我得到了链接并且其工作正常。 当我尝试$Name = 'Teast';(没有“à”symbole)时,它的工作正常。 所以问题是带有符号的名称(éèà...)。 请问如何解决?

3 个答案:

答案 0 :(得分:0)

使用htmlspecialchars方法,

 $Name = 'Teàst';
    $result = file_get_contents('http://example.com/name/' . htmlspecialchars($Name));

答案 1 :(得分:0)

使用

htmlspecialchars()

$Name = 'Teàst';
$Name =htmlspecialchars($Name);
$result = file_get_contents('http://example.com/name/' .$Name);

答案 2 :(得分:0)

此代码适用于我:

<?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
?>