PHP
  Home arrow PHP arrow Page 3 - Defining Some Custom PHP Functions wit...
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 
IBM Developerworks
 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

Defining Some Custom PHP Functions with Yahoo Web Services
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 2
    2008-02-05

    Table of Contents:
  • Defining Some Custom PHP Functions with Yahoo Web Services
  • A procedural approach to Yahoo! Search Service: defining a custom PHP function
  • Using Yahoo! Video Search Service
  • Working with Yahoo! Image Search Service

  • 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

    TestComplete™ automates software testing for a fraction of what the big guys charge. Easy functional and load testing for all Windows, .NET, Java and Web apps. Download a free trial now.

    Defining Some Custom PHP Functions with Yahoo Web Services - Using Yahoo! Video Search Service
    (Page 3 of 4 )

    As you might guess, creating a custom PHP function that uses the Yahoo! Video Search Service is very similar to working with the traditional searches that you saw in the previous section. But to dissipate any possible doubts that you might have regarding this topic, below I included the definition of a brand new PHP function, which implements the helpful Yahoo! Video Search Service.

    Given that, this function, called “getVideoSearchResults()” (yes, my creativity with names continues to blow me away) looks like this:


    // example using Yahoo! Video Search Service - results are displayed in a basic (X)HTML format utilizing an user-defined PHP function


    // define 'getVideoSearchResults()' function

    function getVideoSearchResults($query='madonna',$numResults=10){

    if(!$query){

    throw new Exception('Invalid search query!');

    }

    if(!$numResults||!is_int($numResults)){

    throw new Exception('Invalid number of results!');

    }

    $query=urlencode($query);

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

    // trigger the http request

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

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

    }

    $results=unserialize($results);

    $output='';

    foreach($results[ResultSet][Result] as $result){

    $output.='<h2>'.$result[Title].'</h2><p>'.$result[Summary].'
    </p><p><img src="'.$result[Thumbnail][Url].'" width="'.$result
    [Thumbnail][Width].'" height="'.$result[Thumbnail][Height].'" />
    </p><a href="'.$result[Url].'">'.$result[Url].'</a>';

    }

    return $output;

    }


    Evidently, the definition of the above custom PHP function is very similar to the one I used to work with conventional web searches. Of course, in this specific case, the function will fetch the corresponding search results from a different URL, and format them utilizing different elements of the pertinent output array.

    In addition, below I coded a simple script that first calls the previous “getVideoSearchResults()” PHP function, and then displays on the browser the results produced by the respective video search process. Have a look at the following code sample, please:


    try{

    // call 'getVideoSearchResults()' function

    echo getVideoSearchResults();

    }

    catch(Exception $e){

    echo $e->getMessage();

    exit();

    }


    // displays the following search results


    madonna_2004_montage.wmv

     

    , 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 -


    http://madonnalicious.com/downloads/madonna_2004_montage.wmv

    madonna_earlscourt_190804.wmv


    http://www.madonnalicious.com/downloads/madonna_gelredome
    _090904.wmv madonna 9sep 2004
    http://www.madonnalicious.com/downloads/madonna_earlscourt
    _190804.wmv
    http://www.madonnalicious.com/downloads/madonna_earlscourt
    _dtm_190804.wmv


    http://www.madonnalicious.com/downloads/madonna_earlscourt_190804.wmv

    madonna.al.et.mpg


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


    http://steveswartz.com/madonna.al/madonna.al.et.mpg

    madonna_jonathanross_ruperteverett.wmv


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


    http://www.madonnalicious.com/downloads/madonna
    _jonathanross_ruperteverett.wmv

    madonna_gos_240804.wmv


    has just aired on local TV note the sound sync maybe
    slightly off in the video file Right Click And Save Target As
    Madonnas Visit To Great Ormond Street London Tonight
    Report WMV 128 985Mb Noticias madonna -
    Noticias madonna - Noticias madonna -


    http://madonnalicious.com/downloads/madonna_gos_240804.wmv

    madonna_earlscourt_dtm_190804.wmv


    http://www.madonnalicious.com/downloads/madonna
    _earlscourt_190804.wmv
    http://www.madonnalicious.com/downloads/madonna
    _earlscourt_dtm_190804.wmv
    http://www.madonnalicious.com/downloads/madonna
    _gelredome_music_090904.wmv


    http://www.madonnalicious.com/downloads/madonna_
    earlscourt_dtm_190804.wmv

    The Androids: Do It With Madonna


    Music Video by The Androids. Song: Do It With Madonna.
    Label: Universal Records Released in 2003.


    http://mv.music.yahoo.com/system/admin/tools/getvideo?vid=2156622

    Britney Spears: Me Against The Music - Featuring Madonna


    Music Video by Britney Spears. Song: Me Against The Music -
    Featuring Madonna. Label: Zomba Recording Corp. Released in 2003.


    http://mv.music.yahoo.com/system/admin/tools/getvideo?vid=2158463

    madonna defends adoption decision


    pop star madonna insists she's done nothing wrong in adopting a
    baby boy from malawi, saying she has acted within the law.


    http://cosmos.bcst.yahoo.com/up/yaustralia/news?ch=248153&cl=997154

    Madonna's adoption woes continue


    Madonna's baby adoption has taken yet another turn. The father
    of 13-month-old David claims he never intended his son to be
    adopted by the pop diva, only for her to raise him.


    http://cosmos.bcst.yahoo.com/up/yaustralia/news?ch=248153&cl=1022403


    As you can see, building a custom PHP 5 function that implements the Yahoo! Video Search Service is only a matter of triggering an HTTP request to the correct URL and then parsing the results using a simple “foreach” loop. Period.

    And speaking of working with some of the most popular web services offered by Yahoo!, in the last section of this tutorial I’m going to teach you how to build yet another brand new PHP function, which this time will be tasked with working with its helpful image search service.

    Naturally, in order to learn the details about how this function will be created, you’ll have to click on the link below and keep reading. We’re almost finished!

    More PHP Articles
    More By Alejandro Gervasio


       · In the last article, I discussed how to consume Yahoo! Image Search Service, by mean...
     

       

    PHP ARTICLES

    - 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
    - Working with Multiple Document Nodes with th...

     
    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 6 hosted by Hostway