fixed bug in xml (didn't validate) and used less confusing var names

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@174003 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Aidan Lister 2004-12-03 16:01:33 +00:00
parent 7980b2fa07
commit 9ddd3cfc4f

View file

@ -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 @@ $words = array('apple','pineapple','banana','orange',
$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 @@ foreach ($words AS $word) {
// 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 @@ if ($shortest == 0) {
?>
]]>
</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>,