Jump to content

can someone please explain how this works?


blueman378

Recommended Posts

hi guys, can someone please explain to me what this code does:

 

<?php
function DidYouMean($search){
$content = file_get_contents('http://www.google.com/search?q='.str_replace(' ', '+', $search).'');
preg_match('#<div id=res>(.*?)<div>#', $content, $matches);
$match = str_replace('    Did you mean: ', '', str_replace('  ', '', strip_tags($matches[1])));	
if($match == '' || $match == '    '){
	return 'none';
}else{
  return $match;
}
}

$result = DidYouMean($_GET['q']);

if($result == 'none'){
echo 'You spelt that query correct!';
}else{
echo 'We didn\'t find any results for "'.$_GET['q'].'", did you mean <strong>'.$result.'</strong>?';
}
?>

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.