1

Hi this is the code i am following in my project.

$reports = $this->curl->simple_get('url');
echo is_array($reports)?"Is Array":"Not Array";exit;

It's giving Not Array as output.

I want to convert that into associative array.

Venkata Krishna
  • 4,287
  • 6
  • 30
  • 53

1 Answers1

1

The data you are getting is probably not an array, but a string containing an array structure, e.g. output by print_r(). This kind of data will not automatically be converted back into a PHP array.

To use this you can use a similar solution as brought out here: Create variable from print_r output

it describes the print_r_reverse function that's brought out in php.net page.

how ever - this is kind of an ugly hack. I would suggest to change the page content and use json_encode() in the "url" page, and parse the content using json_decode()

Community
  • 1
  • 1
Tiit
  • 520
  • 4
  • 15
  • what-ever function you have that prints the array to the page, put the variable into a function. So instead of "print $array;" use "print json_encode($array);". At your page just use "json_decode($results);" – Tiit Nov 14 '12 at 11:47
  • you are saying i need to encode the variable in controller file and decode in view file – Venkata Krishna Nov 14 '12 at 11:49