2013-04-18 56 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中将您的数组匹配到相同的格式,要么根据需要更新代码。