2012-04-22 22 views
1

您好我試圖使用此腳本從另一個PHP腳本返回一個值在我的網站上,而不離開頁面,但我得到數字1後的字符串(我假設1是資源編號)這是腳本:如何停止資源顯示在curl_exec結果

<?php 
// create a new cURL resource 
$ch = curl_init(); 

// set URL and other appropriate options 
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/"); 
curl_setopt($ch, CURLOPT_HEADER, false); 

// grab URL and pass it to the browser 
$result = curl_exec($ch); 

// close cURL resource, and free up system resources 
curl_close($ch); 

echo $result; 
?> 

Output is somthing like this: 
"<?php include \\\\localfolder\\blabla\script.php ?>1" 

和1最後是我不想出現的。

感謝,

羅伯特

回答

4

您需要設置CURLOPT_RETURNTRANSFER選項設置爲true:

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 

documentation

CURLOPT_RETURNTRANSFER
TRUE將傳輸返回爲返回值curl_exec()的字符串,而不是直接輸出。

+0

非常感謝,它的工作。 – RobertH 2012-04-22 16:19:57