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
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'));

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.