class keyword_pop
{
function keyword_pop()
{
if($_GET[query]!="")
{
$this->population_form($_GET[query]);
$this->get_population($_GET[query]);
}
else
{
$this->population_form();
}
}
function get_population($keyword)
{
$tmp = explode(",", $keyword);
print("
<table align=\"center\" cellspacing=\"0\" border=\"1\">
<tr>
<td>#</td>
<td>Keyword</td>
<td>Google</td>
<td>MSN</td>
<td>Yahoo</td>
<td>Overture</td>
</tr>
");
if(count($tmp) > 1)
{
$i = 0;
foreach($tmp AS $term)
{
$i++;
$term = $this->fixkeyword($term);
$google = $this->google($term);
$msn = $this->msn($term);
$yahoo = $this->yahoo($term);
$overture = $this->overture($term);
$term = $this->unfixkeyword($term);
print("
<tr>
<td>$i</td>
<td>$term</td>
<td>$google</td>
<td>$msn</td>
<td>$yahoo</td>
<td>$overture</td>
</tr>");
}
}
else
{
$term = $this->fixkeyword($keyword);
$google = $this->google($term);
$msn = $this->msn($term);
$yahoo = $this->yahoo($term);
$overture = $this->overture($term);
$term = $this->unfixkeyword($term);
print("
<tr>
<td>1</td>
<td>$term</td>
<td>$google</td>
<td>$msn</td>
<td>$yahoo</td>
<td>$overture</td>
</tr>");
}
print("</table>");
}
function population_form($query = "")
{
global $_SERVER;
print("
<p>Seperate each keyword with a comma.</p>
<form action=\"$_SERVER[PHP_SELF]\" method=\"GET\">
Keyword(s): <input type=\"text\" name=\"query\" value=\"$query\" /> <input type=\"submit\" name=\"submit\" value=\"Get Keyword Population\" />
</form>
");
}
function google($keyword)
{
$data = file_get_contents("http://www.google.com/search?hl=en&q=$keyword&btnG=Google+Search");
$regexp = '!<b>(.*?)<\/b>!s';
$arrPages = array();
preg_match_all($regexp,$data,$arrPages,PREG_PATTERN_ORDER);
$data = $arrPages[0][5];
if($data == "")
{
$data = "0";
}
return(strip_tags($data));
}
function msn($keyword)
{
$data = file_get_contents("http://search.msn.com/results.aspx?q=$keyword&FORM=MSNH&srch_type=0");
$regexp = '!<h5>(.*?)<\/h5>!s';
$arrPages = array();
preg_match_all($regexp,$data,$arrPages,PREG_PATTERN_ORDER);
$data = $arrPages[0][0];
$tmp = explode(" ",$data);
$data = $tmp[3];
if($data == "")
{
$data = "0";
}
return(strip_tags($data));
}
function yahoo($keyword)
{
$data = file_get_contents("http://search.yahoo.com/search?p=$keyword&sm=Yahoo%21+Search&fr=FP-tab-web-t&toggle=1&cop=&ei=UTF-8");
$regexp = '!<strong>(.*?)<\/strong>!s';
$arrPages = array();
preg_match_all($regexp,$data,$arrPages,PREG_PATTERN_ORDER);
$data = $arrPages[0][2];
if($data == "")
{
$data = "0";
}
return(strip_tags($data));
}
function overture($keyword)
{
$data = file_get_contents("http://inventory.overture.com/d/searchinventory/suggestion/?term=$keyword");
$regexp = '!<td>(.*?)<\/td>!s';
$arrPages = array();
preg_match_all($regexp,$data,$arrPages,PREG_PATTERN_ORDER);
$data = $arrPages[0][0];
if($data == "")
{
$data = "0";
}
$data = strip_tags($data);
$data = str_replace("ย ", "", $data);
return(number_format($data));
}
function fixkeyword($keyword)
{
return(str_replace(" ", "+", $keyword));
}
function unfixkeyword($keyword)
{
return(str_replace("+", " ", $keyword));
}
}
$new = new keyword_pop();