Jump to content

same result show only one time


experts585

Recommended Posts

hi i am using yahoo api search i put a paragraph in a text area explode with ".Dot " and than serah each sentance one by one in yahoo api. Problem is i want when its get all sentancce in one site its give me result one time but my code give result as foreach loop end if it explode 5 time it give me same result 5 time but i want only one time

 

some one help me

 

$queryz=$_REQUEST['query'];
$queryz1=explode('.',$queryz);
foreach ($queryz1 as $k=>$v){
$q = build_query($v);
//exit();
performTask($q);

}



// To cache, we save the result xml to a filename that is a
// hash of the query string.  Note the use of tempnam() and
// rename() to make sure the file is created atomically.
function performTask($q=""){
$cache_file = '/tmp/yws_'.md5('http://search.yahooapis.com/WebSearchService/V1/webSearch'.$q);
if(file_exists($cache_file) && filemtime($cache_file) > (time()-7200)) {
  $raw = file_get_contents($cache_file);
} else {
  $raw = file_get_contents('http://search.yahooapis.com/WebSearchService/V1/webSearch'.$q);
  
  $tmpf = tempnam('/tmp','YWS');
  file_put_contents($tmpf, $raw);
  @rename($tmpf, $cache_file); 
}

$xml = simplexml_load_string($raw);
// Load up the root element attributes
foreach($xml->attributes() as $name=>$attr) $res[$name]=$attr;

$first = $res['firstResultPosition'];
$last = $first + $res['totalResultsReturned']-1;
echo "<p>Matched ${res[totalResultsAvailable]}, showing $first to $last</p>\n";
if(!empty($res['ResultSetMapUrl'])) {
  echo "<p>Result Set Map: <a href=\"${res[ResultSetMapUrl]}\">${res[ResultSetMapUrl]}</a></p>\n";
}
$stored="";
for($i=0; $i<$res['totalResultsReturned']; $i++) {
  
  
  foreach($xml->Result[$i] as $key=>$value) {


	if(stristr($key,'ClickUrl')){	
		if(strpos($stored,$value)){
		continue;
		}
	}  

		if(stristr($key,'Title')) echo "<a href=\"$value\">$value</a> <br /> \n";
		if(stristr($key,'ClickUrl')){echo "Url: <a href=\"$value\">$value</a> <br /> \n"; $stored.=$value;}
		if(stristr($key,'Summary')) echo "$value <br /> \n";
		if(stristr($key,'ModificationDate')) echo "Update: $value From Yahoo <br /> \n";


  }
  echo "<hr />\n";
}
next_prev($res, $first, $last);

}
done();
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.