Commit e38658af authored by Clement GAUDUCHEAU's avatar Clement GAUDUCHEAU
Browse files

tri des dossiers

parent 1964bc11
<html lang="fr">
<head>
<meta charset="utf-8"/>
<title>Test</title>
</head>
<body>
<form method="POST" action="test.php">
<p>
<label for="login">quel mot cherchez vous ?</label>
<input type="text" id="login" name="recherche"/>
</p>
<p>
<input type="submit" value="Envoyer" />
</p>
<p>
<input type="reset" value="Annuler" />
</p>
</form>
</body>
</html>
<?php
$fichier="dico-en_10.txt";
$handle=fopen($fichier,"r");
$content=fread($handle,filesize($fichier));
$split=explode("\n",$content);
$distancemin=PHP_INT_MAX;
$motsPossibles="";
if(isset($_POST['recherche'])){
$input=$_POST['recherche'];
foreach ($split as $motCourant){
//on calcul la distance entre l'input et le mot courant
$lev=levenshtein($input, $motCourant);
if($lev==$distancemin){
$motsPossibles=$motsPossibles.$motCourant."\n";
}
else{
if($lev<$distancemin){
$motsPossibles="";
$motsPossibles=$motsPossibles.$motCourant."\n";
$distancemin=$lev;
}
}
}
echo "Vouliez-vous dire : ".$motsPossibles;
}
?>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment