[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

METAPHONE+LEVENSHTEIN

Posted on 2012-08-24
4
Medium Priority
?
1,091 Views
Last Modified: 2012-08-25
could you show me documentation of
COMPARISONS USING METAPHONE+LEVENSHTEIN
0
Comment
Question by:rgb192
  • 2
4 Comments
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 1336 total points
ID: 38330849
There are some examples on the PHP.net web site.
http://us.php.net/manual/en/function.metaphone.php
http://us.php.net/manual/en/function.levenshtein.php

Metaphone() returns a string.  If you get two different strings from applying metaphone() to two different variables, you can  test the difference with levenshtein().

See also similar_text().
0
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 1336 total points
ID: 38330860
You may also want to run this code and examine the output carefully to see what the programming produced.

<?php // RAY_temp_rgb192.html
error_reporting(E_ALL);
echo "<pre>";

// COPIED FROM THE POST AT EE
$string[1]='hello, how are you';
$string[2]='very different';
$string[3]='hi, how are you';
$string[4]='another string';

$string[] = 'Yousef Islam';
$string[] = 'Yusuf Islam';
$string[] = 'Yusef Islaam';
$string[] = 'Yousif Isla\'am';
$string[] = 'YUSUF Islam';

// COMPARISONS USING SOUNDEX+LEVENSHTEIN
foreach ($string as $x)
{
    // COMPUTE THE SOUNDEX KEY
    $sx = soundex($x);
    echo PHP_EOL . "TESTING <b>$x</b> WITH SOUNDEX() $sx";

    // COMPARE TO THE OTHER STRINGS
    foreach ($string as $y)
    {
        $sy = soundex($y);
        $sl = levenshtein($sx, $sy);
        echo PHP_EOL
        . "SOUNDEX() $sx"
        . " IS $sl DISTANCE FROM $sy";
    }
}
echo PHP_EOL;

// COMPARISONS USING METAPHONE+LEVENSHTEIN
foreach ($string as $x)
{
    // COMPUTE THE METAPHONE KEY
    $sx = metaphone($x);
    echo PHP_EOL . "TESTING <b>$x</b> WITH METAPHONE() $sx";

    // COMPARE TO THE OTHER STRINGS
    foreach ($string as $y)
    {
        $sy = metaphone($y);
        $sl = levenshtein($sx, $sy);
        echo PHP_EOL
        . "METAPHONE() $sx"
        . " IS $sl DISTANCE FROM $sy";
    }
}
echo PHP_EOL;

// COMPARISONS USING SIMILAR_TEXT() BUT SEE THE NOTES HERE BEFORE YOU USE IT!
// http://php.net/manual/en/function.similar-text.php#109507
// COMPARISONS USING SIMILAR_TEXT
foreach ($string as $x)
{
    echo PHP_EOL . "TESTING <b>$x</b> WITH SIMILAR_TEXT()";

    // COMPARE TO THE OTHER STRINGS
    foreach ($string as $y)
    {
        $ss = similar_text($x, $y, $sp);
        echo PHP_EOL
        . "SIMILAR_TEXT() $x"
        . " HAS $ss CHARACTERS IN COMMON WITH $y "
        . '('
        . number_format($sp, 0)
        . '%)'
        ;
    }
}
echo PHP_EOL;

Open in new window

Please post back if you don't understand that or if you have any specific questions, thanks. ~Ray
0
 
LVL 4

Assisted Solution

by:NetExpert_pl
NetExpert_pl earned 664 total points
ID: 38330977
0
 

Author Closing Comment

by:rgb192
ID: 38333592
thanks for webpages and the example code which works for this question
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month19 days, 16 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question