juust ~ php oddities

Unordered list of one element
  • rss
  • begin
  • about
    • vcard
    • WTF is BroJesus
  • php scripts
    • flickr wp widget
    • google multi key serp tool, php script
    • gwt plugin
  • php classes
    • php pagerank class
    • fibonacci class
    • robots.txt parser php class
  • serp
    • serp dashboard wordpress plugin
  • services

google trends II

juust | 22/12/2008

I wanted to reply to a question elsewhere on the site, but a ‘comment’ box isn’t fit for it so I’ll put the reply here. The question was about creating ’search engine friendly’ descriptive URL’s based on keywords from the Google Trends atom feed, listing pages a graph of the trend.

I hacked a quick example together on a subdomain over at trends.trismegistos.net, just to be sure it works.

You can get a site to list http://domain.com/trend_title.html type url’s by using mod_rewrite, an apache module.

In the server directory of the application you can use an .htaccess file to set rules for file access in these folders. When the server gets request from browsers or servers it applies any rewriting rules you define in .htaccess to these requests.

I tried this one :

  1. <ifmodule mod_rewrite.c>
  2.  RewriteEngine On
  3.  RewriteCond %{REQUEST_FILENAME} !-f
  4.  RewriteCond %{REQUEST_FILENAME} !-d
  5.         RewriteRule ^(.*).html /trendinfo.php?title=$1
  6. </ifmodule>

RewriteEngine On
sets the rewrite mechanism on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

tell the apache server that rewriteconditions apply to file-requests that are not an existing file (F) or directory (D). If the requested filename is anywhere in the servers file table, the server dishes out that file, otherwise it will try to apply a RewriteRule. Applying the rule generates a new request, if that returns anything, the server dishes that out, otherwise it returns an htpp-404 ‘file not found’.

The actual url rewrite rule is :
RewriteRule ^(.*).html /trendinfo.php?title=$1
which means :

  • if any filename is requested that satisfies the mask ^(.*).html then
  • take everything before .html
  • add that as variable $1 to trendinfo.php?title=$1
  • see if it sticks

If the browser requests http://domain.com/bob+bowersox.html, the server will assert it is not a file or directory on the server, and test the available rules. When it notices it the requested file ends with .html, it applies the rewrite rule and tries to access http://domain.com/trendinfo.php?title=bob+bowersox.

A browsing user does not notice a thing.

In trendinfo.php I wrote some code to handle the ‘new’ request :

  1. if(!isset($_REQUEST['title'])) {
  2. //if there is no $1, added as title, fake a 404 "file not found" message
  3.         echo 'the emptiness…';
  4. } else {
  5. //get the title from the request
  6.   $mytitle=htmlentities($_REQUEST['title'], ENT_QUOTES, "UTF-8");
  7. //put the google trends graph url together
  8.   $graphurl = 'http://www.google.com/trends/viz?hl=&q=';
  9.   $graphurl .= urlencode($mytitle);
  10.   $graphurl .= '&date=';                        //leave date blank to get the current graph
  11.   $graphurl .= '&graph=hot_img&sa=X';
  12.   echo "<img class=hotGraph width=280 height=190 src='$graphurl'/>";
  13. }

…that outputs the Google trend graph on the url http://domain.com/bob+bowersox.html

I zipped the trends.trismegistos.net program files, but that might be a bit over the top, the download file contains a class that relies on a mysql table being filled every hour with new trends (by cron.php on an apache cron-job), parsing and storing the atom feed of google trends, and listing it as a cross-table in index.php spanning the past 24 hours.

You can also put this in index.php :

  1.   $feed = simplexml_load_file('http://www.google.com/trends/hottrends/atom/hourly');
  2.   $children =  $feed->children('http://www.w3.org/2005/Atom');
  3.   $parts = $children->entry;
  4.   foreach ($parts as $entry) {
  5.      $details = $entry->children('http://www.w3.org/2005/Atom');
  6.       $dom = new domDocument();
  7.      $html=$details->content;
  8.      @$dom->loadHTML($html);
  9.       $anchors = $dom->getElementsByTagName('a');
  10.     foreach ($anchors as $anchor) {
  11.       $url = $anchor->getAttribute('href');
  12.       $urltext = $anchor->nodeValue;
  13.      echo '<a href="'.urlencode($urltext).'.html" target="_blank">'.$urltext.'</a> ';
  14.     }
  15.    }
  16.    unset($dom);
  17.    unset($anchors);
  18.    unset($parts);
  19.    unset($feed);

That lists the current 100 google trends with a link. If you use the .htaccess rewrite rules, the server reroutes all the links to trendinfo.php with descriptive urls.

I hope that helps.

Comments
4 Comments »
Categories
google, php, seo
Tags
google, php, seo, trends
Comments rss Comments rss
Trackback Trackback

the value of google trends

juust | 12/11/2008

I wondered what the value of Google Trends was. I list it on the serp tool and seriously doubted it’s potential, so I did an experiment and decided to use the webmaistro blog, which was doing 1 hit a day, excellent for a test :). Webmaistro is a blogspot blog and Google own blogspot, generally what I publish on it is indexed fast.

I took a ’spicy’ Google Trend with a very characteristic term ‘ocean of glass’, did a search and picked a page gambling that it might be what people are looking for. I published parts of it on the blog, added some links to the source article and to Flickr and posted it.

Using the search phrase ‘ocean of glass‘ as post title and linking to other resources put the post on the details page of Google Trends for the search phrase.

The next hour I got 30 hits on the blog. Checking the referrers shows them all coming from the Google Trends detail page.


google trends referrer for ocean of glass

After an hour the traffic stopped. It seems to me Google Trends has it’s search engine marketing value, as traffic source.

Comments
1 Comment »
Categories
google, sem
Tags
google, sem, trends
Comments rss Comments rss
Trackback Trackback

parsing the google trends atom feed

juust | 07/11/2008

Short and sweet : how to grab the google trends atom feed and parse out the links,
in 15 lines.

  1. $feed = simplexml_load_file('http://www.google.com/trends/hottrends/atom/hourly');
  2. $children =  $feed->children('http://www.w3.org/2005/Atom');
  3. $parts = $children->entry;
  4. foreach ($parts as $entry) {
  5.    $details = $entry->children('http://www.w3.org/2005/Atom');
  6.    $dom = new domDocument();
  7.    @$dom->loadHTML($details->content);
  8.    $anchors = $dom->getElementsByTagName('a');
  9.   foreach ($anchors as $anchor) {
  10.     $url = $anchor->getAttribute('href');
  11.     $urltext = $anchor->nodeValue;
  12.     echo 'Link: <a href="' . $url . '" title="' . $urltext . '">' . $urltext . '</a> ';
  13.   }
  14. }

Requires php with simplexml and dom xml. You could use it for a blogfarm script but that’s about all I can think of.

edited 18-12-08 :
$dom->loadHTML((string) $details->content);
to
@$dom->loadHTML($details->content);

Comments
12 Comments »
Categories
google, php
Tags
google, php, trends
Comments rss Comments rss
Trackback Trackback

Next Entries »

Recent Posts

  • geert wilders
  • gone till september
  • socialize me
  • Pagerank sculpting session
  • wish you were here

click me!
rss
Comments rss
Blog Directory
Web Developement Blogs - BlogCatalog Blog Directory
Listed in LS Blogs the Blog Directory and Blog Search Engine
Blog Flux Directory
joopita.com free web directory and search engine
design by jide
sitemap
22296 confirmed spam kills