aidan Fri Dec 3 11:01:33 2004 EDT
Modified files: /phpdoc/en/reference/strings/functions levenshtein.xml Log: fixed bug in xml (didn't validate) and used less confusing var names http://cvs.php.net/diff.php/phpdoc/en/reference/strings/functions/levenshtein.xml?r1=1.6&r2=1.7&ty=u Index: phpdoc/en/reference/strings/functions/levenshtein.xml diff -u phpdoc/en/reference/strings/functions/levenshtein.xml:1.6 phpdoc/en/reference/strings/functions/levenshtein.xml:1.7 --- phpdoc/en/reference/strings/functions/levenshtein.xml:1.6 Thu Dec 2 12:52:04 2004 +++ phpdoc/en/reference/strings/functions/levenshtein.xml Fri Dec 3 11:01:33 2004 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.6 $ --> +<!-- $Revision: 1.7 $ --> <!-- splitted from ./en/functions/strings.xml, last change in rev 1.12 --> <refentry id="function.levenshtein"> <refnamediv> @@ -122,7 +122,7 @@ <![CDATA[ <?php // input misspelled word -$myWord = 'carrrot'; +$input = 'carrrot'; // array of words to check against $words = array('apple','pineapple','banana','orange', @@ -132,14 +132,14 @@ $shortest = -1; // loop through words to find the closest -foreach ($words AS $word) { +foreach ($words as $word) { // calculate the distance between the input word, // and the current word - $thisLev = levenshtein($myWord, $word); + $lev = levenshtein($input, $word); // check for an exact match - if ($thisLev == 0) { + if ($lev == 0) { // closest word is this one (exact match) $closest = $word; @@ -151,14 +151,14 @@ // if this distance is less than the next found shortest // distance, OR if a next shortest word has not yet been found - if ($thisLev <= $shortest || $shortest < 0) { - // set the closest matchm, and shortest distance + if ($lev <= $shortest || $shortest < 0) { + // set the closest match, and shortest distance $closest = $word; - $shortest = $thisLev; + $shortest = $lev; } } -echo "Input word: $myWord\n"; +echo "Input word: $input\n"; if ($shortest == 0) { echo "Exact match found: $closest\n"; } else { @@ -168,14 +168,14 @@ ?> ]]> </programlisting> - </example> - &example.outputs; - <screen> + &example.outputs; + <screen> <![CDATA[ Input word: carrrot Did you mean: carrot? ]]> - </screen> + </screen> + </example> </para> <para> See also <function>soundex</function>,