必要条件:hunspell
和php5
。
bash的测试代码:
user@host ~/ $ echo 'sagadījās' | hunspell -d lv_LV,en_US
Hunspell 1.2.14
+ sagadīties
- 工作正常。
测试代码(test.php):
$encoding = "lv_LV.utf-8";
setlocale(LC_CTYPE, $encoding); // test
putenv('LANG='.$encoding); // and another test
$raw_response = shell_exec("LANG=$encoding; echo 'sagadījās' | hunspell -d lv_LV,en_US");
echo $raw_response;
返回
Hunspell 1.2.14
& sagad 5 0: tagad, sagad?ties, sagaudo, sagand?, sagar?o
*
*
截图(无法发布包含无效字符的代码):
似乎shell_exec不能正确处理utf-8,或者可能需要一些额外的编码/解码?
编辑:我不得不使用en_US.utf-8来获取有效数据。
1条答案
按热度按时间1aaf6o9v1#
试试这个代码:
不要忘记验证文件的编码(以及您传递的数据的编码)实际上是 * UTF-8 ;- )