1

I have a PHP array, but when I var_dump($array) it returns it as a string.

$array = file_get_contents("http://url.com");

array(1) {
  [0]=>
  string(1874) "array(
  'response'=>array(...

I tried to do var_dump( (array) $array), but that returns the same array as a string again, except this string is now in a single array value.

Any idea on how I can turn this "array" into an actual array?

Thanks!

5
  • Can you provide the code that sets up the contents of the $array variable? Commented Aug 8, 2013 at 2:00
  • I'm doing a file_get_contents of a function that returns a response of array( 'response'=>array('numFound'=>284075,'start'=>0,'docs'=>array( etc.. Commented Aug 8, 2013 at 2:01
  • Sorry I misinterpreted your comment. Commented Aug 8, 2013 at 2:06
  • Maybe eval is a better solution. mixed eval ( string $code ), although it comes with risks. Commented Aug 8, 2013 at 2:08
  • $file_str = file_get_contents("url.com"); $file_arr = explode("\n", $file_str); are you trying to do this? Commented Aug 8, 2013 at 2:18

2 Answers 2

4

file_get_contents returns a string. it is not an array. better option would be to have your function returns a json string and do a json_decode on it from the client side

Sign up to request clarification or add additional context in comments.

Comments

1

http://www.php.net/manual/en/function.print-r.php#93529

or you can resort to the evil eval?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.