[英]Getting failed to open stream: HTTP request failed error with names with symboles
Why I got this error : 为什么我收到此错误:
failed to open stream: HTTP request failed!
无法打开流:HTTP请求失败! HTTP/1.1 404 Not Found
找不到HTTP / 1.1 404
Code : 代码:
$Name = 'Teàst';
$result = file_get_contents('http://example.com/name/' . $Name . );
But when I try echo $result;
但是当我尝试
echo $result;
I got the link and its work fine. 我知道了链接及其工作正常。 And when I try
$Name = 'Teast';
当我尝试
$Name = 'Teast';
(without "à" symbole) its work fine. (不带“à”符号)可以正常工作。 Soo the problem is names with symboles (é è à ...).
这样的问题是带有符号的名称(éèà...)。 How to fix it please ?
请如何解决?
Use htmlspecialchars method, 使用htmlspecialchars方法,
$Name = 'Teàst';
$result = file_get_contents('http://example.com/name/' . htmlspecialchars($Name));
use 采用
htmlspecialchars() htmlspecialchars()
$Name = 'Teàst';
$Name =htmlspecialchars($Name);
$result = file_get_contents('http://example.com/name/' .$Name);
This code works for me: 该代码对我有用:
<?php
$Name = 'Teàst';
$result = file_get_contents('http://example.com/name/' . $Name );
echo $result
?>
And this code works: 这段代码有效:
<?php
$Name = 'Teàst';
$Name = htmlspecialchars($Name);
$result = file_get_contents('http://localhost/temp/' . $Name);
echo $result
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.