Advertisement
Guest User

Pspell CI Controller

a guest
Jun 15th, 2013
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.38 KB | None | 0 0
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class Dw extends CI_Controller {
  4.  
  5.     public function index($word = 'theact')
  6.     {
  7.         $result = array();
  8.  
  9.         $config = pspell_config_create("en", "american");
  10.         pspell_config_personal($config, '/var/www/test/application/controllers/includes/lib/custom.pws');
  11.         pspell_config_mode($config, PSPELL_FAST);
  12.  
  13.         $link = pspell_new_config($config);
  14.         pspell_add_to_personal($link, "Daniweb");
  15.         pspell_save_wordlist($link);
  16.  
  17.  
  18.         if( ! pspell_check($link, $word))
  19.         {
  20.             $suggestions = pspell_suggest($link, $word);
  21.  
  22.             foreach($suggestions as $suggestion)
  23.             {
  24.                 similar_text($word, $suggestion, $percent);
  25.                 if(round($percent) > 70)
  26.                 {
  27.                     $result[] = $suggestion;
  28.                 }
  29.             }
  30.         }
  31.  
  32.         $data['result'] = $result;
  33.  
  34.         $this->load->view('dw/index', $data);
  35.     }
  36.  
  37. }
  38.  
  39.  
  40. /*
  41.  
  42. The view:
  43.  
  44.     <pre><?php
  45.  
  46.     print_r($result);
  47.    
  48.     ?></pre>
  49.    
  50. The pws file (custom.pws):
  51.  
  52.     personal_ws-1.1 en 9
  53.     themouse
  54.     calle
  55.     capanna
  56.     thecat
  57.     revoir
  58.     Daniweb
  59.     thedog
  60.     rndsgr
  61.     casa
  62.  
  63. And then the test links:
  64.  
  65.     http://localhost/dw/index
  66.     http://localhost/dw/index/danweb
  67.     http://localhost/dw/index/thedg
  68.     ...
  69.  
  70. From terminal:
  71.  
  72.     php index.php dw
  73.     php index.php dw index clle
  74.     php index.php dw index danweb
  75.     php index.php dw index cas
  76.  
  77. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement