0

In my application i am making curl request and in response getting an array, but somehow not able to manipulate that array also is_array() not recognize that as an array.

code for curl request is :

$curls="http://localhost/myapp/alertentryxml.php?".$compurl; 

           $ch = curl_init();
           curl_setopt($ch,CURLOPT_URL,$curls);
           curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
           $store = curl_exec($ch);

and generating an multidimensional array from alertentryxml.php with

print_r($data);

$data is multidimensional array.

when i checked response in above $store variable, it shows an array in response but not working as a array. What i have done wrong here? is it possible to send array as a response or not?

4

1 回答 1

1

您不能只做 aprint_r($data)并期望 PHP 能够将其作为数组进行交互,它只是文本。查找print_r的作用:

打印有关变量的人类可读信息

你应该做的是:

alertentryxml.php

echo json_encode($data);

然后在您的 curl 请求中:

$store = json_decode(curl_exec($ch));

在这种情况下,我选择了 JSON,因为它是我个人的偏好,但您也可以将数据作为 XML 或任何其他格式发送,只要您以与另一端的编码相同的方式对其进行解码。

于 2012-12-18T12:35:18.057 回答