The function of the sample program above is to find the pattern in specified string and output the part marked as (.+?).
That was just an example, normally I'll be searching for the pattern in one website source, but it's almost same thing, just that difference string where to search.
Here's the PHP one. It's not exactly the same but it is same principle. This finds the hottest google trends, which are same as what I have in my example - one per line and then prints out all of them together in one line.
Code:
<?php
$newtrends = array();
$newtrendsclean = array();
$outputstring = "";
$logdata = "";
$url = 'http://www.google.com/trends/hottrends/atom/hourly';
$ch = curl_init();
$timeout = SCRAPE_TIMEOUT;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$page = curl_exec($ch);
curl_close($ch);
preg_match_all('(<a href="(.+)">(.*)</a>)siU', $page, $matches);
foreach($matches[2] as $trend){
$trendas = ", $trend";
$trend = addslashes($trend);
$trend = substr($trend,0,99);
echo "$trendas";
}
?>
The trends are originally like this on the website:
Code:
<li><span class="Volcanic equal"><a href="http://www.google.com/trends/hottrends?q=chad+jones&date=2010-6-25&sa=X">chad jones</a></span></li>
<li><span class="On_Fire equal"><a href="http://www.google.com/trends/hottrends?q=peggy+west&date=2010-6-25&sa=X">peggy west</a></span></li>
<li><span class="Spicy up4"><a href="http://www.google.com/trends/hottrends?q=taste+of+chicago+2010&date=2010-6-25&sa=X">taste of chicago 2010</a></span></li>
<li><span class="Spicy equal"><a href="http://www.google.com/trends/hottrends?q=kate+gosselin+botox&date=2010-6-25&sa=X">kate gosselin botox</a></span></li>
<li><span class="Spicy down2"><a href="http://www.google.com/trends/hottrends?q=jobbie+nooner+2010&date=2010-6-25&sa=X">jobbie nooner 2010</a></span></li>
<li><span class="Spicy equal"><a href="http://www.google.com/trends/hottrends?q=nba+draft+grades&date=2010-6-25&sa=X">nba draft grades</a></span></li>
in other words, one per line just like in my example, and the PHP code outputs the trends all in one line like this:
Code:
, chad jones, peggy west, taste of chicago 2010, kate gossellin botox etc.