PHP
  Home arrow PHP arrow Page 3 - Fetching Search Results as Serialized ...
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Fetching Search Results as Serialized Arrays with Yahoo Web Services and PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-01-15

    Table of Contents:
  • Fetching Search Results as Serialized Arrays with Yahoo Web Services and PHP 5
  • Displaying web services search results in XML format
  • Next Example
  • Serving outputs of Yahoo! Web services as serialized PHP arrays
  • Iterating over array elements with PHP 5

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    Dell PowerEdge Servers

    Fetching Search Results as Serialized Arrays with Yahoo Web Services and PHP 5 - Next Example
    (Page 3 of 5 )

    For the sake of clarity and considerations of length, we placed the second example on a new page. Here it is: 

    <!--

    ws02.search.scd.yahoo.com uncompressed/chunked Wed
    Oct 17 07:30:35 PDT 2007

    -->

    */

    // example using Yahoo! Video Search Web Service - search results
    are displayed in raw XML format

    try{

    $request='http://search.yahooapis.com/VideoSearchService/V1/
    videoSearch?appid=Your-AP-ID&query=madonna&results=4';

    // trigger the http request

    if(!$results=file_get_contents($request)){

    throw new Exception('Error requesting Yahoo! Web service');

    }

    // display the results in XML format

    header('Content-type:text/xml;charset=iso-8859-1');

    echo $results;

    }

    catch(Exception $e){

    echo $e->getMessage();

    exit();

    }

    /* displays the following

    <ResultSet xsi:schemaLocation="urn:yahoo:srchmv
    http://api.search.yahoo.com/VideoSearchService/V1/
    VideoSearchResponse.xsd" totalResultsAvailable="10365"
    totalResultsReturned="4" firstResultPosition="1">

    <Result>

    <Title>madonna_2004_montage.wmv</Title>

    <Summary>, interviews, news footage and tour clips from
    New York and Paris....here's hoping 2005 is just as busy!
    Right Click And Save Target As Madonna's 2004 Movie Montage
    (WMV) - 7:44 - 21.8Mb Noticias madonna - Noticias madonna -
    Noticias madonna </Summary>

    <Url>http://madonnalicious.com/downloads/madonna_2004_
    montage.wmv</Url>

    <ClickUrl>http://madonnalicious.com/downloads/madonna_
    2004_montage.wmv</ClickUrl>

    <RefererUrl>http://www.descargaarchivos.com/noticias/index.php?
    query=madonna&type=video</RefererUrl>

    <FileSize>22902293</FileSize>

    <FileFormat>msmedia</FileFormat>

    <Height>240</Height>

    <Width>320</Width>

    <Duration>464</Duration>

    <Streaming>false</Streaming>

    <Channels>2</Channels>

    <Thumbnail>

    <Url>http://scd.mm-so.yimg.com/image/1702970034</Url>

    <Height>105</Height>

    <Width>140</Width>

    </Thumbnail>

    </Result>

    <Result>

    <Title>madonna_earlscourt_190804.wmv</Title>

    <Summary>http://www.madonnalicious.com/downloads/
    madonna_gelredome_090904.wmv madonna 9sep
    2004http://www.madonnalicious.com/downloads/
    madonna_earlscourt_190804.wmv
    http://www.madonnalicious.com/downloads/
    madonna_arlscourt_dtm_190804.wmv</Summary>

    <Url>http://www.madonnalicious.com/downloads/madonna_
    earlscourt_190804.wmv</Url>

    <ClickUrl>http://www.madonnalicious.com/downloads/
    madonna_earlscourt_190804.wmv</ClickUrl>

    <RefererUrl>http://lounge.cosmopolitan.nl/messages/1/
    14515.html?1095249265</RefererUrl>

     <FileSize>42149471</FileSize>

    <FileFormat>msmedia</FileFormat>

    <Height>240</Height>

    <Width>320</Width>

    <Duration>543</Duration>

    <Streaming>false</Streaming>

    <Channels>2</Channels>

    <Thumbnail>

    <Url>http://scd.mm-so.yimg.com/image/1700163527</Url>

    <Height>105</Height>

    <Width>140</Width>

    </Thumbnail>

    </Result>

    <Result>

    <Title>madonna.al.et.mpg</Title>

    <Summary>Summary: Watch Madonna on Entertainment Tonight :
    Madonna discusses American Life with ET .mpg Noticias madonna -
    Noticias madonna - Noticias madonna -</Summary>

    <Url>http://steveswartz.com/madonna.al/madonna.al.et.mpg</Url>

    <ClickUrl>http://steveswartz.com/madonna.al/madonna.al.et.mpg</ClickUrl>

    <RefererUrl>http://www.descargaarchivos.com/noticias/index.php?
    query=madonna&type=video</RefererUrl>

    <FileSize>12821508</FileSize>

    <FileFormat>mpeg</FileFormat>

    <Height>240</Height>

    <Width>352</Width>

    <Duration>73</Duration>

    <Streaming>false</Streaming>

    <Channels>2</Channels>

    <Thumbnail>

    <Url>http://scd.mm-so.yimg.com/image/1794815224</Url>

    <Height>98</Height>

    <Width>145</Width>

    </Thumbnail>

    </Result>

    <Result>

    <Title>madonna_jonathanross_ruperteverett.wmv</Title>

    <Summary>And Save Target As Friday Night With Jonathan Ross -
    Rupert Everett On Madonna (WMV) - 1:25 - 2.45Mb Noticias
    madonna Noticias madonna - Noticias madonna</Summary>

    <Url>http://www.madonnalicious.com/downloads/
    madonna_jonathanross_ruperteverett.wmv</Url>

    <ClickUrl>http://www.madonnalicious.com/downloads/
    madonna_jonathanross_ruperteverett.wmv</ClickUrl>

    <RefererUrl>http://www.descargaarchivos.com/noticias/index.php?
    query=madonna&type=video</RefererUrl>

    <FileSize>2579729</FileSize>

    <FileFormat>msmedia</FileFormat>

    <Height>240</Height>

    <Width>320</Width>

    <Duration>85</Duration>

    <Streaming>false</Streaming>

    <Channels>2</Channels>

    <Thumbnail>

    <Url>http://scd.mm-so.yimg.com/image/1703473304</Url>

    <Height>105</Height>

    <Width>140</Width>

    </Thumbnail>

    </Result>

    </ResultSet>

    <!--

    ws05.search.scd.yahoo.com uncompressed/chunked Wed Oct 17
    07:41:48 PDT 2007

    -->

    */


    Despite the lengthy source code of the two previous hands-on examples, the truth is that they’re very easy to understand. In the first case, a GET http request is triggered to the corresponding Yahoo! URL in order to use its popular Web Search Service. Note that in the query string I included first the corresponding application ID (which can be obtained by completing a simple registration form), then the search term “Madonna,” and finally the number of results that should be returned to the client.

    Next, the pertinent results are displayed on the browser in XML, wrapped by a pair of <ResultSet></ResultSet> nodes. Very simple to code and read, right?

    And finally, the last example looks very similar to the first one, but in this case, the Video Web Search service is used instead of performing a common search.

    So far, so good. At this time, hopefully you've recalled how to implement the previous Yahoo! Web Search Services directly from some simple PHP 5 scripts. What’s next? Well, as I explained in the beginning of this article, Yahoo! provides web developers with an additional “output” option for specifying in the query string which format the pertinent search result should be returned to the browser.

    If you're working with PHP, this “output” variable must have a value of “php” (output=php), which will cause all of the search results to be returned to the client in the form of a serialized PHP array. As you’ll realize, this feature can help, largely parsing these results using only a few PHP array processing functions, but this topic will be discussed in detail in the section to come.

    So read the next few lines. They’re just one click away

    More PHP Articles
    More By Alejandro Gervasio


       · Over the course of this second chapter of the series, you’ll learn how to fetch the...
     

       

    PHP ARTICLES

    - Setting Up a Web-based Image Hosting Service
    - Comparing Files and Databases with PHP Bench...
    - Setting Up a Web-Based Image Gallery
    - Using Timers to Benchmark PHP Applications
    - Benchmarking Applications with PHP
    - Setting Up a Web-Based File Manager: PHPfile...
    - Developing a Modular Class For a PHP File Up...
    - Setting Up a Web-Based File Manager: bfExplo...
    - Defining a Custom Function for File Uploader...
    - Parsing Child Nodes with the DOM XML extensi...
    - Creating an Error Handling Module for a PHP ...
    - Accessing Attributes and Cloning Nodes with ...
    - Retrieving Information on Selected Files wit...
    - Handling HTML Strings and Files with the DOM...
    - Building File Uploaders with PHP 5

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway