|
CodeUsage
# phpYahoo: Code Usage IntroductionExample Usage Below are a few examples for using phpYahoo. DetailsInvoking the phpYahoo Class include_once('api/phpYahoo.php'); include_once('api/phpYahooSearch.php'); $ysearch = new phpYahooSearch('jrrxraqsrfgviny'); $ysearch->enableCache('db'); $searchtext= $GET['searchtext']; Yahoo! Web Search ` $params = array("query"=>$keyword,"region"=>"us","type"=>"any","results"=>"20","start"=>$start); $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 $params = array("query"=>$keyword,"region"=>"us","type"=>"any","results"=>"20","start"=>$start); $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 $params = array("query"=>$keyword,"region"=>"us","type"=>"any","results"=>"20","start"=>$start); $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 .= "</table></p>\n";$html_images .= "</tr><tr valign=top>"; $i=0;} echo $html_images; |
Sign in to add a comment
