blueman378 Posted May 2, 2008 Share Posted May 2, 2008 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>?'; } ?> Link to comment https://forums.phpfreaks.com/topic/103874-can-someone-please-explain-how-this-works/ Share on other sites More sharing options...
jonsjava Posted May 2, 2008 Share Posted May 2, 2008 it searches for what you wanted using google, and it will ask you if you meant to search for something else, if google posts back "did you mean" Link to comment https://forums.phpfreaks.com/topic/103874-can-someone-please-explain-how-this-works/#findComment-531702 Share on other sites More sharing options...
blueman378 Posted May 2, 2008 Author Share Posted May 2, 2008 oh right thanks, so i guess you coul,d use this as a cheap way to get a suggestion on a search thing like run it if there were no results? Link to comment https://forums.phpfreaks.com/topic/103874-can-someone-please-explain-how-this-works/#findComment-531707 Share on other sites More sharing options...
jonsjava Posted May 2, 2008 Share Posted May 2, 2008 something like that. Link to comment https://forums.phpfreaks.com/topic/103874-can-someone-please-explain-how-this-works/#findComment-531708 Share on other sites More sharing options...
blueman378 Posted May 2, 2008 Author Share Posted May 2, 2008 any ideas on how effectivei t would b? Link to comment https://forums.phpfreaks.com/topic/103874-can-someone-please-explain-how-this-works/#findComment-531723 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.