Shoutbox

Searching for similar variable - php - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: Searching for similar variable - php (/showthread.php?tid=91278)

Searching for similar variable - php by stoshrocket on 06-30-2009 at 08:15 PM

I've got a script that searches a simple text files line by line for a stated string, but I also wanted to search for "similar" strings. So, for example, if we had the following in list.txt

code:
frig
frag
brag
grand
train

and "frugle" was seached for, it would return, "did you mean: frig? frag?" or something similar.

any ideas how I'd go about it?
RE: Searching for similar variable - php by prashker on 06-30-2009 at 08:41 PM

Do something with similar_text()

php code:
<?php
$list = file('list.txt');
$string = "dog";

foreach $list as $tree {
     similar_text($string, $tree, $percent);
    if ($percent > 75) {
        echo 'Did you mean' . $tree . '?';
    }
}
?>

RE: Searching for similar variable - php by Mike on 06-30-2009 at 08:42 PM

This may help a little (especially the first result): http://www.google.com/search?hl=el&client=firefox...%F4%E7%F3%E7&meta= :)


RE: Searching for similar variable - php by stoshrocket on 06-30-2009 at 09:23 PM

Both are perfect, thanks guys!