Home arrow PHP arrow Page 3 - Defining Some Custom PHP Functions with Yahoo Web Services

Using Yahoo! Video Search Service - PHP

Welcome to the fourth installment of the series “Using Yahoo! Web Services with PHP 5.” Made up of six approachable tutorials, this series provides you with the right pointers to start using these useful web services within the context of your PHP 5-driven applications. It complements the corresponding theoretical concepts with a decent variety of hands-on examples.

  1. Defining Some Custom PHP Functions with Yahoo Web Services
  2. A procedural approach to Yahoo! Search Service: defining a custom PHP function
  3. Using Yahoo! Video Search Service
  4. Working with Yahoo! Image Search Service
By: Alejandro Gervasio
Rating: starstarstarstarstar / 3
February 05, 2008

print this article



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){


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



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




// trigger the http request


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




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

</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:


// call 'getVideoSearchResults()' function

echo getVideoSearchResults();


catch(Exception $e){

echo $e->getMessage();



// displays the following search results



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



_090904.wmv madonna 9sep 2004



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



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 -



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 -





The Androids: Do It With Madonna

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


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.


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.


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.


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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: