/*------------------------------------------------------------------------------------------------- Ping Google image search http://code.google.com/apis/websearch/docs/reference.html -------------------------------------------------------------------------------------------------*/ # Settings $keyword = "puppies"; $howManyResults = 8; # Max is 8 # What page of search results should it pull from? $randomPage = rand(1, 50); # Pick a random page. Make the last number smaller if you wan't more relevant results. # Ping Google $url = "http://ajax.googleapis.com/ajax/services/search/images?start=" . $randomPage . "&rsz=" . $howManyResults . "&v=1.0&q=" . $keyword; echo "URL We're fetching from: <a href='{$url}'>{$url}</a><br/><br/>"; # Make cURL call $curlResults = makeCurlCall($url); # Parse the results of the cURL call into an array $images = stringExtractor($curlResults, 'unescapedUrl":"', '","'); # Loop through the array showing all the images foreach ($images as $thisImage) { echo "<img style='width:100px; height:100px' src='{$thisImage}'/><br/>"; } /*------------------------------------------------------------------------------------------------- makeCurlCall -------------------------------------------------------------------------------------------------*/ function makeCurlCall($url) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $curlResults = curl_exec($ch); curl_close($ch);
<title>cURL example for Yahoo News</title> <!-- OKTOSHOW --><a href='/classes/viewSource/?path=<?php echo $_SERVER['PHP_SELF']; ?> ' target='_blank'>View Source</a><br/><br/><br/> <?php # What URL should we download? $url = "http://rss.news.yahoo.com/rss/mostviewed"; echo "URL We're fetching from: <a href='{$url}'>{$url}</a><br/><br/>"; # Make curl call $curlResponse = makeCurlCall($url); # Parse the results of the curl call, grabbing all the title instances $titles = stringExtractor($curlResponse, '<title>', '</title>'); # Loop through the titles printing them all out foreach ($titles as $thisTitle) { echo $thisTitle . "<br/>"; } /*------------------------------------------------------------------------------------------------- makeCurlCall -------------------------------------------------------------------------------------------------*/ function makeCurlCall($url) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $curlResults = curl_exec($ch); curl_close($ch); return $curlResults; } /*-------------------------------------------------------------------------------------------------