phpYahoo: An Unofficial Yahoo Search API
jay
*updated - 2007-01-26*
phpYahoo is a class written in PHP5 that act's as a wrapper for Yahoo's! Web Search API. Methods process the response XML and return an array of data to make development easier. With this class you can search for Yahoo! Web content, Yahoo! Videos or Yahoo! Images.
This class follows a similar pattern like phpNapster class.
Example Usage
Below are a few examples for using phpYahoo.
Invoking the phpYahoo Class
PHP:
-
require_once('phpYahoo.php');
-
$y = new phpYahoo('YAHOOAPPID');
-
-
$searchtext= $_GET['searchtext'];
Yahoo! Web Search
PHP:
-
$results_web = $y->searchWeb($searchtext,20); //search text and number of results MAX:50
-
-
foreach($results_web as $result) {
-
$html_web .= "<p style='background:".$bgcolor.";'>\n";
-
-
//display a link to the search item result
-
$html_web .= "<a href='".$result['clickUrl']."' title='".$result['displayUrl']."'>".$result['title']."</a>";
-
$html_web .= "<br>";
-
-
//display the summary
-
$html_web .= $result['summary'];
-
$html_web .= "<br>";
-
$html_web .= "</p>\n";
-
$count++;
-
}
-
echo $html_web;
Yahoo! Video Search
PHP:
-
$results_web = $y->searchVideos($searchtext,20); //search text and number of results MAX:50
-
-
foreach($results_video as $result) {
-
$html_video .= "<p>\n";
-
$html_video .= "<a href='".$result['clickUrl']."' title='".$result['displayUrl']."'>".$result['title']."</a>";
-
$html_video .= "<br>";
-
$html_video .= $result['summary'];
-
$html_video .= "<br>";
-
-
//display a thumbnail of the video with a link
-
$html_video .= "<a href='".$result['url']."' title='".$result['title']."'><img src='".$result['thumbnail']."'></a>";
-
$html_video .= "<br>";
-
$html_video .= "</p>\n";
-
}
-
echo $html_video ;
Yahoo! Image Search
PHP:
-
$results_images = $y->searchImages($searchtext,20);
-
-
$html_images .= "<p>\n";
-
$html_images .= "<table><tr valign=top>\n";
-
$i=0;
-
foreach($results_images as $result) {
-
$html_images .= "<td width='23%' align='center'>\n";
-
$html_images .= "<a href='".$result['url']."' title='".$result['title']."'><img src='".$result['thumbnail']."' border='0'></a>";
-
$html_images .= "<br>";
-
-
$html_images .= "</td>\n";
-
$i++;
-
if($i==3) {
-
$html_images .= "</tr><tr valign=top>";
-
$i=0;
-
}
-
}
-
$html_images .= "</table></p>\n";
-
-
echo $html_images;
Posted in phpYahoo |






