- 철자 체크 , language spelling check extension

php7.4-enchant - 스펠링 체크, Enchant module for PHP
https://www.php.net/manual/en/enchant.installation.php

//--------------------------------
php.ini 수정

extension=php_enchant.dll



//-------------------------------
// 에러 발생
- 사전파일이 있어야 한다
$r = \enchant_broker_init();
enchant_broker_list_dicts() = null
https://www.php.net/manual/en/enchant.examples.php


//---------------
사전 다운로드

//-------------------------
OpenOffice 에서 다운로드
http://extensions.services.openoffice.org/dictionary

다운로드 받은 extension의 압축을 풀면 
en-US.aff , en-US.dic 파일이 존재

dictionarys.7z
1.13MB



//-------------------------
* 파이어폭스에서 다운로드
https://addons.mozilla.org/ko/firefox/language-tools/

부가기능 설치
설치된 폴더로 이동
C:\Users\userID\AppData\Roaming\Mozilla\Firefox\Profiles\5i6ybdip.default-1580818658521\extensions
@unitedstatesenglishdictionary.xpi 압축을 풀면
en-US.aff , en-US.dic 파일이 존재 

파이어폭스의 한글 스펠 체커 사전파일에는 문제가 있어 보인다, OpneOffice 파일 사용 권장


//-----------------------
* 파일 이름 변경
-> 이름 변경 '-' => '_'  언더스코어로 변경
en_US.aff , en_US.dic

//--------------
* 파일 복사
[PHP폴더]/share/myspell/dicts  폴더로 복사

 

 


//---------------
// 확인 코드 소스
https://www.php.net/manual/en/enchant.examples.php

- 한글 철자 체크
$tag = 'ko_KR';//'ko_KR';//'en_US';
        $r = \enchant_broker_init();
        $bprovides = \enchant_broker_describe($r);
        echo "Current broker provides the following backend(s):\n";
        dump($bprovides, $r);
        $dicts = \enchant_broker_list_dicts($r);
        dump($dicts);
        if (enchant_broker_dict_exists($r,$tag)) {
            $d = enchant_broker_request_dict($r, $tag);
            $dprovides = enchant_dict_describe($d);
            echo "dictionary $tag provides:\n";
            $word = '가나리';//"contryer";//"soong";
            $wordcorrect = enchant_dict_check($d, $word);
            dump($word , $dprovides, $wordcorrect);
            if (!$wordcorrect) {
                $suggs = enchant_dict_suggest($d, $word);
                echo "Suggestions for $word:";
                dump($suggs);
            }
            enchant_broker_free_dict($d);
        } else {
        }
        enchant_broker_free($r);

반응형
Posted by codens