bha*_*ath 3 php arrays json curl return
我在这里有一个表格 - http://example.com/palreg.php
一旦人们注册,我将向他们发送一封电子邮件,其链接将允许他们编辑他们的详细信息(我知道这是一种疯狂的做事方式,但我正在研究其他人的代码所以不要介意)例如这样的url http://example.com/palreg.php?paliD=1234,当他们转到那个页面时,表单将填充他们的信息,以便他们可以进行更改.
现在问题是数据库在不同的站点,并且必须将信息传递到该站点以执行选择操作,为此我使用cURL发送信息,如此
$url = "http://example2.com/processXML.php";
$xmlStr will be like this
<table>tab_name</table>
<action>select</action>
<palid>1234</palid>
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, 'xmlstr='.$xmlStr);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
Run Code Online (Sandbox Code Playgroud)
在另一端(http://example2.com/processXML.php)我将xml转换为数组并执行查询以根据发送的id选择pal信息.
现在真正的问题是如何将检索到的pal信息(如xml或json或数组)发送回来,以便我可以使用返回的数据填充表单.
我也可以return $dataArray;进行processXML.php并能够抓住它吗?
可以让事情更清楚,我所做的processXML.php是检索结果集并执行此操作
print json_encode($resultArray);
Run Code Online (Sandbox Code Playgroud)
我不应该打印或返回
谢谢,如果事情不清楚,请告诉我.
只需按需要对其进行编码,然后将其回显到页面即可.你的$ data =将包含回显的内容.个人偏好一直是使用JSON,因为它很容易丢弃.如在
//Bunch of DB stuff..
$row=mysql_fetch_however_you_handle_it();
echo json_encode($row);
//on your receiving end, that just did the cURL send,
$row=json_decode($data,true);//decode the JSON straight into an array...
Run Code Online (Sandbox Code Playgroud)