2013-04-18 78 views
0

我想運行PHP中的一個GET捲曲擺脫PHP B.數據PHP - 運行GET捲曲,得到結果

這是一個PHP的例子

//next example will recieve all messages for specific conversation 
$service_url = 'http://localhost/test/getFrom.php?id=1'; 
$curl = curl_init($service_url); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
$curl_response = curl_exec($curl); 
if ($curl_response === false) { 
    $info = curl_getinfo($curl); 
    curl_close($curl); 
    die('error occured during curl exec. Additioanl info: ' . var_export($info)); 
} 
curl_close($curl); 
$decoded = json_decode($curl_response); 
if (isset($decoded->response->status) && $decoded->response->status == 'ERROR') { 
    die('error occured: ' . $decoded->response->errormessage); 
} 
echo 'response ok!'; 
var_export($decoded->response); 
(我從這裏 http://support.qualityunit.com/061754-How-to-make-REST-calls-in-PHP了)

我試過了這個例子,以及(Trying to use curl to do a GET, value being sent is allows null

在PHP B. 將獲得ID,運行一些腳本,將生成一個數組。

我想從B本陣列A.當一個請求從B.

GET

問題是,我怎麼沒有陣列可的B傳遞給

B就只能運行

請給點建議謝謝。

回答

0

您提供的代碼需要返回一個JSON編碼數組。最簡單的方法是使用JSON在PHP B中編碼您的數組並將其回顯到頁面。

然後CURL將能夠讀取PHP B的內容,根據需要進行解碼和處理。

// PHP B 

<?php 

    // Check for $_GET params 

    // Get ID 
    $id = $_GET['id']; 

    // Do processing, query etc 
    .... 

    // Format and display array as JSON 
    echo(json_encode($result_array)); 
    die(); 

?> 

還要注意:

if (isset($decoded->response->status) && $decoded->response->status == 'ERROR') { 
    die('error occured: ' . $decoded->response->errormessage); 
} 

代碼期待以特定的方式進行格式化的陣列。所以要麼在PHP B中將您的數組匹配到相同的格式,要麼根據需要更新代碼。