Example Code Usage
jay
Example Usage
Here are 3 examples of using phpYahoo to search for the Web, Videos and Images.
PHP:
-
include_once('api/phpYahoo.php');
-
-
$y = new phpYahoo('jrrxraqsrfgviny');
-
$y->enableCache('db');
-
-
$searchtext= $GET['searchtext'];
Yahoo! Web Search
PHP:
-
$results_web = $y->searchWeb($params); //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($params);
-
-
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($params);
-
-
OR
-
-
$results_images = $y->searchImages($searchtext);
-
$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 Documentation |






