HomePHP Fetching Search Results as Serialized Arrays with Yahoo Web Services and PHP 5
Fetching Search Results as Serialized Arrays with Yahoo Web Services and PHP 5
In this second article of the series dealing with the implementation of some of the most useful web services offered by Yahoo! with PHP 5, I’ll show you how to parse the results returned by a determined web search service using a few array PHP processing functions.
Many modern web sites use popular web services, such as image and video searches. Their correct implementation has proven to be very useful when it comes to attracting new visitors that are looking for a richer and more productive surfing experience.
However, as you’ll possibly know, using a given web service in conjunction with a powerful server-side scripting language like PHP 5 can be quite challenging. This is particularly true if the web service must be implemented from scratch using WSDL (Web Service Description Language).
Fortunately, there are some frameworks available on the web that will let you easily use a determined web service without having to deal directly with data delivered in XML format. And that’s precisely the case with Yahoo! Web Search Services, which can be directly invoked within your own PHP applications by writing only a few lines of code.
Naturally, if you already went through the first article of the series, then you’ll surely be very familiar with using these web services provided by Yahoo! straight from a simple PHP script. As you’ll possibly recall, during that tutorial I built some illustrative hands-on examples aimed at demonstrating how to utilize Yahoo!’s Image and Video Search Services, among others, using only small pieces of PHP 5 code.
The results returned by these hands-on examples, after querying one of the aforementioned web services, always outputted in XML format. This can be rather intimidating for some PHP developers who want to implement those services within the context of their own applications.
Nevertheless, the good news is that all of the web services offered by Yahoo! permit the specification of an additional “output=php” parameter within the corresponding query string, which indicates that all of the results retrieved should be returned in the form of a serialized PHP array. Indeed, as you can see, this feature simplifies displaying the respective search results in a more readable format, since PHP has plenty of native functions aimed at processing array elements.
Now, having introduced the primary subject of this tutorial, let’s learn how to fetch results returned by the different Yahoo! Search Web Services in the form of serialized PHP arrays. Let’s get started!