Advertisement
Guest User

Untitled

a guest
Jul 31st, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. <?php
  2. $input = '';
  3. $hasil = '';
  4. $wordsArray = array(
  5. 'apple', 'pineapple', 'banana', 'orange', 'jeruk',
  6. 'jorok', 'modifikasi', 'radish', 'carrot', 'pea',
  7. 'bean', 'potato', 'makan', 'google', 'menghadirkan',
  8. 'balap', 'mobilio'
  9. );
  10.  
  11. echo '<pre>';
  12. print_r($wordsArray);
  13. echo '</pre>';
  14.  
  15. if (isset($_POST['input']))
  16. {
  17. $input = $_POST['input'];
  18.  
  19. foreach ($wordsArray as $word)
  20. {
  21. $lev = levenshtein($input, $word);
  22. $closest[$lev] = $word;
  23. }
  24.  
  25. ksort($closest);
  26. $shortest = min(array_keys($closest));
  27.  
  28. echo '<pre>';
  29. print_r($closest);
  30. echo '</pre>';
  31.  
  32. if ($shortest == 0)
  33. {
  34. $hasil = $closest[$shortest]; //klo sama cetak
  35. }
  36. else
  37. {
  38. $hasil = 'Did you mean: '.$closest[$shortest].' ?'; // apakah yg anda maksud ??
  39. }
  40. }
  41. ?>
  42.  
  43. <div class="container">
  44. <div class="row">
  45. <div class="left-text"><h2>Masukan Teks</h2></div>
  46. <form method="POST" action="#">
  47. <p>
  48. <textarea name="input" id="input" cols="100" rows="10" tabindex="4"><?php echo $input ?></textarea>
  49. </p>
  50. <br>
  51. <input type="submit" value="Proses" />
  52. </form>
  53. </div>
  54. <div class="row">
  55. <h2>Teks Hasil Edit</h2>
  56. <textarea class="form-control" cols="100" rows="10"><?php echo $hasil ?></textarea>
  57. </div>
  58. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement