PHP.mk документација

pspell_suggest

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

function.pspell-suggest.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека function.pspell-suggest.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
pspell_suggest

Референца за `function.pspell-suggest.php` со подобрена типографија и навигација.

function.pspell-suggest.php

pspell_suggest

(PHP 4 >= 4.0.2, PHP 5, PHP 7, PHP 8)

pspell_suggestПредложи правописи на збор

= NULL

pspell_suggest(PSpell\Dictionary $dictionary, string $word): array|false

pspell_suggest() враќа низа од можни правописи за дадениот збор.

Параметри

dictionary

Еден PSpell\Dictionary instance.

word

Тестираниот збор.

Вратени вредности

Враќа низа од можни правописи.

Дневник на промени

Верзија = NULL
8.1.0 На dictionary параметарот очекува PSpell\Dictionary инстанца сега; претходно, а resource се очекуваше.

Примери

Пример #1 pspell_suggest() example

<?php
$pspell
= pspell_new("en");

if (!
pspell_check($pspell, "testt")) {
$suggestions = pspell_suggest($pspell, "testt");

foreach (
$suggestions as $suggestion) {
echo
"Possible spelling: $suggestion<br />";
}
}
?>

Белешки од корисници 1 белешка

webmaster at hostpure dot com
21 години пред
It seems if you are trying to do something similar to the Google 'Did you mean:' suggestions and are selecting the first word given by the pspell_suggest() function, then it will not work well with custom dictionaries and replacements. Take the following code for example:

<?php
    $pspell_config = pspell_config_create("en");
    pspell_config_personal($pspell_config, "/home/user/public_html/custom.pws");
    pspell_config_repl($pspell_config, "/home/user/public_html/custom.repl");
    $pspell_link = pspell_new_config($pspell_config);

    $words = preg_split ("/\s+/", $query);
    $ii = count($words);

    global $spellchecked;
    $spellchecked = "";
    
    for($i=0;$i<$ii;$i++){

        if (pspell_check($pspell_link, $words[$i]))
        {
            $spellchecked .= $words[$i]." ";
        }
        else
        {
            $erroneous = "yes";
            $suggestions = pspell_suggest($pspell_link, $words[$i]);
            $spellchecked .= $suggestions[0]." ";
        }
    }
    if($erroneous == "yes")
    {
        echo "Did you mean: <i>".$spellchecked."?";
    }
    else
    {
        echo $spellchecked . " is a valid word/phrase";
    }
?>

This works fine most of the time, and gives suggestions to what you meant when inserting a spelling mistake with most inputs. However, if you specify a custom replacement and then search for the misspelt word that you specified, then if it is not the first returned suggestion it wont be used in the 'Did you mean' end result. What you need to do is open up the custom dictionary using fopen and fread, and then for each of the suggested words, check if they are in the dictionary. If the suggested word is in the custom dictionary then use it in the 'Did you mean' part, if not, discard it and try the next. Hope this helps anyone who comes across this problem with trying to get more accurate suggestions.
На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.