Jump to content

[SOLVED] file_get_contents() to array??


severndigital

Recommended Posts

ok .. so i have a url i can access with various get variables to pull information i need.

like

site.com/?method=search&q=searchstring&option=file

 

the result is echoed on the screen as an array.

 

that looks like this

 

Array
(
    [0] => Array
        (
            [HANDLE] => Collection-58148
            [DISPLAYNAME] => Collection Title
        )

)

 

in another script on a completely different sever that DOES NOT have access to the source code of the first script.

 

I am running this

 

$result = file_get_contents('linkwith?all=the&get=information');

 

how do I get the text output of the array back into an array? I'm not sure what php function (s) to use to do this.

 

Thanks,

 

C

Link to comment
https://forums.phpfreaks.com/topic/167280-solved-file_get_contents-to-array/
Share on other sites

yes, i would recommend using JSON, as it's a more universal format (not PHP specific), but you can also use serialize()/unserialize() or var_export()/eval()

 

JSON:

echo json_encode($array);

$array = json_decode(file_get_contents('linkwith?all=the&get=information'));

ok .. so after a quick look I am using PHP 5.1.6 which does not have Json included.

 

no worries though I installed the PECL extension version of the json functions, since upgrading to 5.2 is not an option at this point.

 

looks like everything is going to work though.

 

Thanks much.

 

-P

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.