Jump to content

[SOLVED] Help!Saving generated web search result by yahoo using linkdomain


jigen7

Recommended Posts

i have here a function that returns the number of total websites that was being link to a certain site using the yahoo linkdomain:domain.com - site:domain.com, the problem is I also want to save those url into a some kind of variable for example an array so that i can echo/print them if i want them anybody who has an idea?? 

 

function yahoo_linkdomain($url){

$site = fopen('http://search.yahoo.com/search?ei=UTF-8&fr=sexp-rd&p=linkdomain%3A'.urlencode($url).'+-site%3A'.urlencode($url),'r');

while($cont = fread($site,1024657)){ 

$total .= $cont; 

fclose($site); 

$match_expression = '/about (.*) for/Us'; 

preg_match($match_expression,$total,$matches); 

return $matches[1];

 

}

I would change the function.

 

Instead of counting what you are currently matching on....I would preg match on a URL, then return an array of the URLs.  Then you could call count($foundurls) to get the number and still have the urls stored too.

I dont use preg_match, even though I should.  my way would work but is uhhh, unorthidox 

 

but it would look something like

unction yahoo_linkdomain($url){

$site = fopen('http://search.yahoo.com/search?ei=UTF-8&fr=sexp-rd&p=linkdomain%3A'.urlencode($url).'+-site%3A'.urlencode($url),'r');

  while($cont = fread($site,1024657)){ 

      $total .= $cont; 

  fclose($site); 

$urls = array();

while(1)

{

$total =  strstr($total, "http://");

if(!$total)

{

    break;

}

$endpos = strpos($total,"'");

$thelink= substr($total,0,$endpos);

array_push($urls, $thelink); 

}

  return($urls);

}

 

My jenky code is basically what preg_match does except preg_match is way more efficient.  but mine is a good exercise in learning what it preg_match does on a basic level

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.