The Little Guy Posted January 1, 2010 Share Posted January 1, 2010 I want to make an API for my site in the near future, I would like to know a few things... Say I want the user to be able to do: $thing->search('some string'); on their server, and say I want to return an Array that may look like this: Array ( [0] => Array ( [id] => 12923551 [title] => 'This is the title' [info] => 'This is some extra information' ) [1] => Array ( [id] => 32456581 [title] => 'This is another title' [info] => 'This is some extra information' ) ) Then the user can use that array to do what they want on their server. Is this possible, if so how do you do this? Link to comment https://forums.phpfreaks.com/topic/186884-an-api/ Share on other sites More sharing options...
Brandon_R Posted January 2, 2010 Share Posted January 2, 2010 An api usually outputs the data as XML so you can have id, title etc as XML tags and the value of that inside the tag. You would need to use a mysql query to pull the data and then use DOM etc to insert the data into a tag and output it. Then the client site would use DOM to get the XML and parse it and output it to their visitors. Link to comment https://forums.phpfreaks.com/topic/186884-an-api/#findComment-986909 Share on other sites More sharing options...
The Little Guy Posted January 2, 2010 Author Share Posted January 2, 2010 so... basically I would have to write a method to convert XML output to Arrays? Link to comment https://forums.phpfreaks.com/topic/186884-an-api/#findComment-986913 Share on other sites More sharing options...
trq Posted January 2, 2010 Share Posted January 2, 2010 You could just as easily send your data as a serialized array. Link to comment https://forums.phpfreaks.com/topic/186884-an-api/#findComment-986916 Share on other sites More sharing options...
The Little Guy Posted January 2, 2010 Author Share Posted January 2, 2010 So... After reading, what I understand, is that I would do something like this on my server: $arr = array(1,2,3,4,5); echo serialize($arr); Then on the server that is using the API, they would have this: // $opt contains the string that was returned using cURL print_r(unserialize($opt)); Would this be correct? Link to comment https://forums.phpfreaks.com/topic/186884-an-api/#findComment-986923 Share on other sites More sharing options...
trq Posted January 2, 2010 Share Posted January 2, 2010 Something like that, yeah. Link to comment https://forums.phpfreaks.com/topic/186884-an-api/#findComment-986927 Share on other sites More sharing options...
The Little Guy Posted January 2, 2010 Author Share Posted January 2, 2010 Something like that, yeah. Did you have something different in mind? Link to comment https://forums.phpfreaks.com/topic/186884-an-api/#findComment-986929 Share on other sites More sharing options...
trq Posted January 2, 2010 Share Posted January 2, 2010 No. Link to comment https://forums.phpfreaks.com/topic/186884-an-api/#findComment-986934 Share on other sites More sharing options...
The Little Guy Posted January 2, 2010 Author Share Posted January 2, 2010 OK Thanks! Link to comment https://forums.phpfreaks.com/topic/186884-an-api/#findComment-986935 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.