Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $input = '';
- $hasil = '';
- $wordsArray = array(
- 'apple', 'pineapple', 'banana', 'orange', 'jeruk',
- 'jorok', 'modifikasi', 'radish', 'carrot', 'pea',
- 'bean', 'potato', 'makan', 'google', 'menghadirkan',
- 'balap', 'mobilio'
- );
- echo '<pre>';
- print_r($wordsArray);
- echo '</pre>';
- if (isset($_POST['input']))
- {
- $input = $_POST['input'];
- foreach ($wordsArray as $word)
- {
- $lev = levenshtein($input, $word);
- $closest[$lev] = $word;
- }
- ksort($closest);
- $shortest = min(array_keys($closest));
- echo '<pre>';
- print_r($closest);
- echo '</pre>';
- if ($shortest == 0)
- {
- $hasil = $closest[$shortest]; //klo sama cetak
- }
- else
- {
- $hasil = 'Did you mean: '.$closest[$shortest].' ?'; // apakah yg anda maksud ??
- }
- }
- ?>
- <div class="container">
- <div class="row">
- <div class="left-text"><h2>Masukan Teks</h2></div>
- <form method="POST" action="#">
- <p>
- <textarea name="input" id="input" cols="100" rows="10" tabindex="4"><?php echo $input ?></textarea>
- </p>
- <br>
- <input type="submit" value="Proses" />
- </form>
- </div>
- <div class="row">
- <h2>Teks Hasil Edit</h2>
- <textarea class="form-control" cols="100" rows="10"><?php echo $hasil ?></textarea>
- </div>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement