severndigital Posted July 24, 2009 Share Posted July 24, 2009 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 More sharing options...
rhodesa Posted July 24, 2009 Share Posted July 24, 2009 do you have any control over the output of the first server? Link to comment https://forums.phpfreaks.com/topic/167280-solved-file_get_contents-to-array/#findComment-882025 Share on other sites More sharing options...
severndigital Posted July 24, 2009 Author Share Posted July 24, 2009 yes. right now the function that is being called is set to print_r() the array. should I change that? Link to comment https://forums.phpfreaks.com/topic/167280-solved-file_get_contents-to-array/#findComment-882027 Share on other sites More sharing options...
rhodesa Posted July 24, 2009 Share Posted July 24, 2009 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 https://forums.phpfreaks.com/topic/167280-solved-file_get_contents-to-array/#findComment-882030 Share on other sites More sharing options...
severndigital Posted July 24, 2009 Author Share Posted July 24, 2009 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 https://forums.phpfreaks.com/topic/167280-solved-file_get_contents-to-array/#findComment-882062 Share on other sites More sharing options...
rhodesa Posted July 24, 2009 Share Posted July 24, 2009 you can also get php functions for encoding JSON if you wanted again, another php-specific option is the serialize/unserialize functions Link to comment https://forums.phpfreaks.com/topic/167280-solved-file_get_contents-to-array/#findComment-882065 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.