【问题标题】:pspell returns question marks(�)pspell 返回问号(�)
【发布时间】:2015-06-21 16:55:21
【问题描述】:

我尝试使用以下命令在 Ubuntu 可信赖的发行版上安装 pspell:

sudo apt-get install libpspell-dev sudo apt-get install php5-pspell sudo apt-get install aspell-he

由于安装过程中没有返回错误,因此该过程似乎已成功。

但是,当我在实际操作中尝试此操作时,我得到了一系列问号 (�):

pspell_config_create("he");
$t = pspell_new('he');

$suggestions = pspell_suggest($t, 'דבל');


return view('master', compact('suggestions')); 
// the above line can be swapped with"
// print_r($suggestions);
// and the result stays the same

我使用视图的原因是因为我认为网页可能需要设置一些字符集,所以我使用 HTML5 文档结构来实现,但结果保持不变。

我的 HTML 标记:

<!doctype html>
<html lang="he">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    סתם טקסט לבדיקה
    <?php print_r($suggestions); ?>
</body>
</html>

从那里返回的结果:

סתם טקסט לבדיקה Array ( [0] =&gt; � [1] =&gt; � [2] =&gt; � [3] =&gt; � [4] =&gt; � [5] =&gt; � [6] =&gt; � )

我还尝试过另一个测试:

return pspell_check($t, 'הגדא') ? 'there is' : 'nope';

由于某种原因,对于任何给定的单词,它都返回“nope”,这意味着pspell_check 返回了false

知道如何解决这个问题吗?

编辑:

当尝试检索结果的长度时:

<!doctype html>
<html lang="he">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
@foreach($suggestions as $suggestion)
    {{ strlen($suggestion) }} <br>
@endforeach
</body>
</html>

结果是:

1 
1 
1 
1 
1 
1 
1 

这意味着pspell_suggest 方法返回的结果可能在从 aspell 字典中检索数据时出现问题?

【问题讨论】:

    标签: php ubuntu aspell pspell


    【解决方案1】:

    这看起来像编码问题。您应该将UTF-8 用于HTML 内容(检查您的页面&lt;head&gt; 并检查您是否设置了encding,但是您还必须使用以相同UTF-8 编码的内容填充您的页面。如果(这经常发生)您的 PHP 文件不是 UTF8,那么您将遇到编码不匹配和 代替。

    【讨论】:

    • 嘿。我试过了。查看我编辑的答案以查看我正在使用的 HTML。回复是:סתם טקסט לבדיקה Array ( [0] =&gt; � [1] =&gt; � [2] =&gt; � [3] =&gt; � [4] =&gt; � [5] =&gt; � [6] =&gt; � )。不幸的是,问题仍然存在
    【解决方案2】:

    由于每个单词检查都返回相同的结果,这让我怀疑传递给pspell_suggest 函数的值可能已损坏。

    我所做的只是告诉 pspell 使用 UTF-8:

    $t = pspell_new('he', "", "", "utf-8");
    

    这解决了问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-22
      • 1970-01-01
      • 2015-06-13
      • 2011-05-31
      • 1970-01-01
      • 2014-12-31
      相关资源
      最近更新 更多