what is my website worth ? (php fetching)

What is the worth of my puny blog ? Here’s two snippets (download) to grab estimates from two sites. The first one is business-opportunities.biz, the second webvaluer.org.

According to www.business-opportunities.biz my blog is worth 1700 dollar. Their estimate is derived from the Technorati blog cosmos so it only works for blogs that are registered there.

  1. function what_my_site_is_worth_according_to_business_opportunities($url)
  2. {
  3.     $html=file_get_contents('http://www.business-opportunities.biz/projects/how-much-is-your-blog-worth/submit/?url='.$url);
  4.     $cut1=explode('is worth',$html);
  5.     $cut2=explode('< /p>',$cut1[1]);
  6.     $result=trim($cut2[0]);
  7.     if(strlen($result)==0) return(0);
  8.     return($result);
  9. }

use

  1. echo what_my_site_is_worth_according_to_business_opportunities('www.juust.org');

That returns in my case $1,693.62

According to webvaluer.org my website is worth $7,549 US dollar. Their site returns a value for every type of site. In the page source there is a span format tag around the text

  1. < h1>juust.org Estimated Worth < span style="color:green; font-weight:bold;">$7,549 USD< /span>< /h1>

I cut it before and after the span tag, and use the php function strip_tags() to remove the span tag, and only the text string remains.

  1. function what_my_blog_is_worth_according_to_webvaluer($url)
  2. {
  3.     $html=file_get_contents('http://www.webvaluer.org/us/'.$url);
  4.     $cut1=explode('Estimated Worth', $html);
  5.     $cut2=explode('< /h1>',$cut1[1]);
  6.     $result=(trim($cut2[0]));
  7.     if(strlen($result)==0) return(0);
  8.     return(strip_tags($result));
  9. }

use :

  1. echo what_my_blog_is_worth_according_to_webvaluer('www.juust.org');

How to make your own php fetch function :

  • check the result page html source
  • see what tag or phrase comes before the text you want (‘Estimated Worth’)
  • use explode() or split() to cut the source up in pieces on that phrase
  • take the piece after the phrase (arrays are 0-based,use cut1[1] to get the second piece)
  • cut that up at the first tag (‘< /h1>‘) after the text you want
  • use the first piece (cut2[0]) that holds the text you want

It’s easier to use source splitting for this sort of fetching than regular expressions, which is sooner meant to retrieve generic patterns (email addresses and stuff) from lots of pages (preg_match()), or an array of similar string from one page (preg_match_all(), for serp pages or report tables).

note : my php code highlighter refuses to display html tags in functions proper so in the code I added a blank space : $cut2=explode(‘< /p>‘,$cut1[1]);
Remove the blanks from the html tag in the function for it to work proper or use the text source
.

Posted in php and tagged .

Leave a Reply

Your email address will not be published. Required fields are marked *