簡體   English   中英

無法打開流:HTTP請求失敗,錯誤名稱帶有符號

[英]Getting failed to open stream: HTTP request failed error with names with symboles

為什么我收到此錯誤:

無法打開流: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';
    $result = file_get_contents('http://example.com/name/' . htmlspecialchars($Name));

采用

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM