Jump to content

basic search?


ok

Recommended Posts

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;
	}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/120288-basic-search/#findComment-619709
Share on other sites

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.