background image

$dictionary

 = 

array

(

“php”, “javascript”, “css”
);

$word

 = “japhp”;

$best_match

 = 

$dictionary

[0];

$match_value

 = levenshtein(

$dictionary

[0], 

$word

);

foreach

(

$dictionary

 

as

 

$w

) {

$value

 = levenshtein(

$word

$w

);

if

$value

 < 

$match_value

 ) {

$best_match

 = 

$w

;

$match_value

 = 

$value

;

}
}

echo

 “Did you mean the ‘

$best_match

' category?”;

10. 

glob

()

glob

()会让你觉得用 opendir(), readdir()和

closedir

()来寻找文件非常蠢。

foreach

 (

glob

(“*.php”) 

as

 

$file

)

echo

 “

$file

\n”;