Tuesday, February 13, 2007

Function GetYahooRes()

This function just construct the search string that will fetch the desired page, and sends this search string to the function ReadPage. And the return value from the func Readpage is forwarded to the function ParseYahooRes().

Function ReadPage

This is not a class function.
It resides outside of the class definition.

function readpage($url,$till,$occ,$morelen)

//readpage("http://search.yahoo.com/search?p=link%3Ahttp%3A%2F%2F".$this->url."+-".$this->GetDomainName(),
//
http://search.yahoo.com/search?p=link%3Ahttp%3A%2F%2Fwww.salesforce.com+-www.salesforce.com
//"

Search Results

",
//1,
//100);

$url contains the link that will fetch the search result.
$till contains a string, in this case /"

Search Results

/"
$occ contains a number, in this case 1
$morelen contains a number, in this case 100.


And I don't like the idea of this function.
It is trying to do several things, and the logic is not clear.

I think I am going to revert to the Fetch_content function.


ParseYahooRes

function ParseYahooRes($str)

--
Return Value: False if $str == Null String.
0(zero) if no search result is found.
GetNumber($s) if success.

* The GetNumber($s) function removes commas from a string and returns as an Integer.

--

function ParseYahooRes($str){
if ($str=="")
return false;

$s=explode("

Search Results

",$str,2);
if (count($s)==1)
$s=explode("

Directory Results

",$str,2);
$s=$s[1];

$s=explode(" of about ",$s,2);
if (count($s)==1)
return 0; // No results
$s=$s[1];
$s=explode(" ",$s,2);
$s=$s[0];
echo '*'.$s.'*';
return $this->GetNumber($s);
}