ok Posted August 19, 2008 Share Posted August 19, 2008 i'm designing a basic search when i type this 'carbon' for example. it should display related words. CarbonAutdit.com Carbonneering.com Carbonfactory.net CArbonbuyers.cn etc... what function or could you show me exampe that fits for this please. thank you. Quote Link to comment https://forums.phpfreaks.com/topic/120288-basic-search/ Share on other sites More sharing options...
natbob Posted August 19, 2008 Share Posted August 19, 2008 Here http://www.php.net/manual/en/function.levenshtein.php is a link to a function which finds how close two words are in spelling. It may be of some help. Here is code implementing the function. It goes through a query result and finds the closest match to $_GET['word']. <?php while($row = mysql_fetch_assoc($result)) { $lev = levenshtein(strtolower($_GET['word']), strtolower($row['name']), 1, 1, 1); if ($lev == 0) { $close = $word; $short = 0; $id = $row['id']; break; } if ($lev <= $short || $short < 0) { $close = $word; $ans = $row['name']; $id = $row['id']; $short = $lev; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/120288-basic-search/#findComment-619709 Share on other sites More sharing options...
dezkit Posted August 19, 2008 Share Posted August 19, 2008 SELECT * FROM tablename WHERE field1 LIKE "%$search%" ORDER BY field1 DESC Quote Link to comment https://forums.phpfreaks.com/topic/120288-basic-search/#findComment-619713 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.