2015-03-31 84 views
0

爲什麼我得到這個錯誤:入門未能打開流:HTTP請求與名稱失敗的錯誤與symboles

未能打開流:HTTP請求失敗! HTTP/1.1 404未找到

代碼:

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

但是當我嘗試echo $result;我得到的鏈接,其做工精細。 當我嘗試$Name = 'Teast';(沒有「à」符號)它的工作正常。 Soo問題是帶有符號的名字(éèà...)。 如何解決它?

回答

0

使用用htmlspecialchars方法,

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

但我的結果中包含的名稱和當名稱更改爲'茶st'的結果 – vladeuurs255s 2015-03-31 07:52:44

+0

@ vladeuurs255s檢查我的回答 – 2015-03-31 07:53:08

0

使用

htmlspecialchars()

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

我不能執行我的代碼的其餘未能打開流:HTTP請求失敗! HTTP/1.1 400錯誤請求 – vladeuurs255s 2015-03-31 08:24:31

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

@ vladeuurs255s你有一些進步與你的問題? – 2015-05-01 18:52:01

相關問題