2013-05-01 50 views
0

我需要在我的代碼中創建一個新的PHP HTTP請求。它返回一個json編碼的數據數組。如何創建新的HTTP請求並且不重定向到該位置?PHP在代碼中創建請求

謝謝。

+0

你的問題是混亂的,你可以請澄清你正在努力做得更好。 – skrilled 2013-05-01 23:16:36

+0

您可能正在尋找'fopen($ url);'或類似的東西,但沒有更多細節,很難確定。 – 2013-05-01 23:18:39

+0

你的意思是你正在嘗試生成一個帖子來運行一個PHP腳本,它將返回一些數據(以json格式),以便您可以在導致POST發生的頁面中使用它。如果閱讀AJAX並讓生活更輕鬆,請查閱jQuery(一個JavaScript框架) – RiggsFolly 2013-05-01 23:21:20

回答

0

假設你正在試圖獲得一個JSON文件,並把它變成一個數組:

$content = file_get_contents('http://www.example.com/test.json'); 
$json_array = json_decode($content); 
print_r($json_array) 
0

這是你在找什麼:http://codular.com/curl-with-php

// Get cURL resource 
$curl = curl_init(); 
// Set some options - we are passing in a useragent too here 
curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => 1, 
    CURLOPT_URL => 'http://stackoverflow.com' 
)); 
// Send the request & save response to $resp 
$resp = curl_exec($curl); 
// Close request to clear up some resources 
    curl_close($curl); 


//For testing only 
print_r('<pre>'); 
print_r($resp);die();