Hi Everyone,
As part of an import routine I am working on I am trying to find the MOST likely data to match a bunch of fields from the items listed in the tables.
So really I am trying to do a sounds like with an integer value return to work out which value may be the closest to the input string.
Then I will sort a list and present it in MOST similar to LEAST similar order.
My actual project involves lots of fields and reading in lines by lines. So below I have put together a simple version that when I get this right then I can apply to my project.
I have tried the following so far:
<?php
$myinput = "jelly";
$mytest1 = "nelly";
$mytest2 = "jelly";
$mytest3 = "jellies";
$mytest4 = "Bellyse";
echo similar_text($mytest1,$myinput, $perc) . "perc: " .$perc. "<br>";
echo similar_text($mytest2,$myinput, $perc) . "perc: " .$perc. "<br>";
echo similar_text($mytest3,$myinput, $perc) . "perc: " .$perc. "<br>";
echo similar_text($mytest4,$myinput, $perc) . "perc: " .$perc. "<br>";
echo levenshtein($mytest1,$myinput) . "<br>";
echo levenshtein($mytest2,$myinput) . "<br>";
echo levenshtein($mytest3,$myinput) . "<br>";
echo levenshtein($mytest4,$myinput) . "<br>";
echo strcmp($mytest1,$myinput) . "<br>";
echo strcmp($mytest2,$myinput) . "<br>";
echo strcmp($mytest3,$myinput) . "<br>";
echo strcmp($mytest4,$myinput) . "<br>";
?>
similar_text with a percentage comparison seems the best so far.
Anyone else have any better examples of comparison and other functions please ?
Many thanks in advance
R
ASKER
ASKER
ASKER
ASKER
$myinput = "Jelly";
$strings = [
"nelly", "jellies", "jelly", "nelly", "kelly", "JELLY", "jilly", "jel", "jell"
];
ASKER
ASKER
ASKER
ASKER
PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.
TRUSTED BY
ASKER
If I search for Tin I get the following ranking:
Tin
Thin
Tin Hat
Where Tin and Tin Hat are the top results.
Any ideas please? I have seen reference to sounds like.... Please advise.
Thanks
R