09-01-2007, 03:20 PM
|
#6 (permalink)
|
|
Junior Member
Join Date: 03-20-07
Posts: 7
Latest Blog: None
|
I use the Overture keyword tool, Here is a script for it will help at all.
PHP Code:
<?php
class KeywordManager
{
//class variables
var $keywordArray = array();
function KeywordManager()
{
//init function
}
function saveKeywordFile($fileName)
{
/*
saves file with specified array of keywords and file name
example: saveKeywordFile("saveas.txt",$keywordArray)
*/
$keywordArray = $this->keywordArray;
if (count($keywordArray) > 0)
{
if (file_exists($fileName))
{
//File name already exist
return 0;
}
$filePointer = fopen($fileName,"w");
if (!is_resource($filePointer))
{
//Error creating file
return 0;
}
foreach ($keywordArray as $keyword)
{
fwrite($filePointer,$keyword."\n");
}
return 1;
} else
{
//Keyword array is empty
return 0;
}
}
function loadKeywordFile($fileName)
{
/*
loads a keyword file, returns array on success and 0 on failure
example: loadKeywordFile("keywords.txt");
*/
if (is_readable($fileName))
{
$filePointer = fopen($fileName,"r");
if (!is_resource($filePointer))
{
//No resource
return 0;
}
$fileData = "";
while (!feof($filePointer))
{
$fileData .= fgets($filePointer,128);
}
$keywordArray = explode("\n",$fileData);
foreach ($keywordArray as $keyword)
{
array_push ($this->keywordArray,$keyword);
}
return ($this->keywordArray);
} else
{
//File not readable
return 0;
}
}
function overtureKeywordSuggestions ($baseKeyword)
{
$curlHandle = curl_init();
curl_setopt($curlHandle,CURLOPT_URL,"http://inventory.uk.overture.com/d/searchinventory/suggestion/");
curl_setopt($curlHandle,CURLOPT_USERAGENT,"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2");
curl_setopt($curlHandle,CURLOPT_RETURNTRANSFER,1);
curl_setopt($curlHandle,CURLOPT_REFERER,"http://inventory.uk.overture.com/d/searchinventory/suggestion/");
curl_setopt($curlHandle,CURLOPT_POST,1);
curl_setopt($curlHandle,CURLOPT_POSTFIELDS,"mkt=uk&lang=en_GB&term=".urlencode($baseKeyword)."&x=11&y=5");
$returnedHtml = curl_exec($curlHandle);
preg_match_all("|<font face=\"verdana,sans-serif\" size=1 color=#000000>(.*)</a></td>|U",$returnedHtml,$keywordMatches);
foreach ($keywordMatches[1] as $keyword)
{
if (array_search($keyword,$this->keywordArray)==0)
{
array_push($this->keywordArray,$keyword);
} else
{
//Keyword exist
return 0;
}
}
return $this->keywordArray;
}
}
?>
|
|
|