PHP
  Home arrow PHP arrow Page 2 - Fetching Search Results as Serialized Arrays with Yahoo Web Services and PHP 5
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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: starstarstarstarstar / 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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    Fetching Search Results as Serialized Arrays with Yahoo Web Services and PHP 5 - Displaying web services search results in XML format
    ( Page 2 of 5 )

    In case you didn’t have the chance to read the first article of the series, I’m going to list the source code of a couple of practical examples that I developed in that tutorial. Reviewing these examples will help you to more quickly grasp how to invoke different Yahoo! Search Services directly from your own PHP 5 scripts.

    Are you ready to digest all this useful material? Great! These hands-on examples look like this: 

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

    try{

    $request='http://search.yahooapis.com/WebSearchService/V1/webSearch?
    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:srch
    http://api.search.yahoo.com/WebSearchService/V1/WebSearchResponse.xsd"
    type="web" totalResultsAvailable="65700000" totalResultsReturned="4"
    firstResultPosition="1" moreSearch="/WebSearchService/V1/webSearch?
    query=madonna&appid= Your-AP-ID&region=us">

    <Result>

    <Title>Madonna</Title>

    <Summary>Official site of pop diva Madonna, with news, music, media, and fan
    club.</Summary>

    <Url>http://www.madonna.com/</Url>

    <ClickUrl>http://uk.wrs.yahoo.com/_ylt=A0Je5aqLHBZHhCMBkjbdmMwF;
    _ylu=
    X3oDMTB2cXVjNTM5BGNvbG8DdwRsA1dTMQRwb3MDMQRzZWMDc3IEdnRpZAM-
    /SIG=11buvpo71/EXP=1192717835/**http%3A//www.madonna.com/</ClickUrl>

    <DisplayUrl>www.madonna.com/</DisplayUrl>

    <ModificationDate>1192518000</ModificationDate>

    <MimeType>text/html</MimeType>

    <Cache>

    <Url>http: //uk.wrs.yahoo.com/_ylt=A0Je5aqLHBZHhCMBkzbdmMwF;
    _ylu=X3oDMTBwOHA5a2tvBGNvbG8DdwRwb3MDMQRzZWMDc3IEdnRpZAM-
    /SIG=15ipfur0l/EXP=1192717835/**http%3A//66.218.69.11/search/cache%
    3Fei=UTF-8%26appid= Your-AP-ID %26query=madonna%26results=4%
    26u=www.madonna.com/%26w=madonna%26d=ZjRUGudmPoUK%26icp=1%
    26.intl=us

    </Url>

    <Size>18519</Size>

    </Cache>

    </Result>

    <Result>

    <Title>MySpace.com - Madonna - Pop / Rock - www.myspace.com/madonna</Title>

    <Summary>Madonna MySpace page with news, blog, music downloads, desktops,
    wallpapers, and more.</Summary>

    <Url>http://www.myspace.com/madonna</Url>

    <ClickUrl>http://uk.wrs.yahoo.com/_ylt=A0Je5aqLHBZHhCMBlTbdmMwF;
    _ylu=
    X3oDMTB2ZjQ4dDExBGNvbG8DdwRsA1dTMQRwb3MDMgRzZWMDc3IEdnRpZAM-
    /SIG=11i0d3vg8/EXP=1192717835/**http%3A//www.myspace.com/madonna

    </ClickUrl>

    <DisplayUrl>www.myspace.com/madonna</DisplayUrl>

    <ModificationDate>1192518000</ModificationDate>

    <MimeType>text/html</MimeType>

    <Cache> <Url>http://uk.wrs.yahoo.com/_ylt=A0Je5aqLHBZHhCMBljbdmMwF;
    _ylu=X3oDMTBwZG5hOWwzBGNvbG8DdwRwb3MDMgRzZWMDc3IEdnRpZAM-
    /SIG=15pd5lje6/EXP=1192717835/**http%3A//66.218.69.11/search/cache%
    3Fei=UTF-8%26appid= Your-AP-ID %26query=madonna%26results=4%
    26u=www.myspace.com/madonna%26w=madonna%26d=Z-awV-dmPogu%
    26icp=1%26.intl=us

    </Url>

    <Size>138157</Size>

    </Cache>

    </Result>

    <Result>

    <Title>Madonna (I)</Title>

    <Summary>Facts and filmography for the singer and actress.</Summary>

    <Url>http://www.imdb.com/name/nm0000187</Url>

    <ClickUrl>http://uk.wrs.yahoo.com/_ylt=A0Je5aqLHBZHhCMBmDbdmMwF;
    _ylu=
    X3oDMTB2M3MzdmZoBGNvbG8DdwRsA1dTMQRwb3MDMwRzZWMDc3IEdnRpZAM-
    /SIG=11m0tssno/EXP=1192717835/**http%
    3A//www.imdb.com/name/nm0000187

    </ClickUrl>

    <DisplayUrl>www.imdb.com/name/nm0000187</DisplayUrl>

    <ModificationDate>1192518000</ModificationDate>

    <MimeType>text/html</MimeType>

    <Cache>

    <Url>http://uk.wrs.yahoo.com/_ylt=A0Je5aqLHBZHhCMBmTbdmMwF;
    _ylu=
    X3oDMTBwZ2dpZ2ZkBGNvbG8DdwRwb3MDMwRzZWMDc3IEdnRpZAM-
    /SIG=15tn2vem4/EXP=1192717835/**http%3A//66.218.69.11/search/cache%
    3Fei=UTF-8%26appid= Your-AP-ID %26query=madonna%26results=4%
    26u=www.imdb.com/name/nm0000187%26w=madonna%26d=DgNm1OdmPoYh%
    26icp=1%26.intl=us

    </Url>

    <Size>97655</Size>

    </Cache>

    </Result>

    <Result>

    <Title>Madonna Song Lyrics: Home Page</Title>

    <Summary>Extensive collection of Madonna lyrics, organized by album. Includes lyrics to singles.</Summary>

    <Url>http://www.madonnalyrics.org/</Url>

    <ClickUrl>http://uk.wrs.yahoo.com/_ylt=A0Je5aqLHBZHhCMBmzbdmMwF;
    _ylu=
    X3oDMTB2OWM1MXQ5BGNvbG8DdwRsA1dTMQRwb3MDNARzZWMDc3IEdnRpZAM-
    /SIG=11h8ms67a/EXP=1192717835/**http%3A//www.madonnalyrics.org/

    </ClickUrl>

    <DisplayUrl>www.madonnalyrics.org/</DisplayUrl>

    <ModificationDate>1181286000</ModificationDate>

    <MimeType>text/html</MimeType>

    <Cache>

    <Url>http://uk.wrs.yahoo.com/_ylt=A0Je5aqLHBZHhCMBnDbdmMwF;
    _ylu=X3oDMTBwYzFnNmkxBGNvbG8DdwRwb3MDNARzZWMDc3IEdnRpZAM-
    /SIG=15o801re7/EXP=1192717835/**http%3A//66.218.69.11/search/cache%
    3Fei=UTF-8%26appid= Your-AP-ID %26query=madonna%26results=4%
    26u=www.madonnalyrics.org/%26w=madonna%26d=WcyQU-dmPohM%26icp=1%
    26.intl=us

    </Url>

    <Size>18749</Size>

    </Cache>

    </Result>

    </ResultSet>



     
     
    >>> More PHP Articles          >>> More By Alejandro Gervasio
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT