PHP 8.4.1 Released!

pspell_check

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

pspell_checkПроверяет слово

Описание

pspell_check(PSpell\Dictionary $dictionary, string $word): bool

pspell_check() проверяет орфографию слова.

Список параметров

dictionary

Экземпляр класса PSpell\Dictionary.

word

Проверяемое слово.

Возвращаемые значения

Возвращает true, если орфография верна, в противном случае возвращает false.

Список изменений

Версия Описание
8.1.0 Параметр dictionary теперь ожидает экземпляр класса PSpell\Dictionary; раньше параметр ждал ресурс (resource).

Примеры

Пример #1 Пример использования pspell_check()

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

if (
pspell_check($pspell, "testt")) {
echo
"Это верное написание";
} else {
echo
"К сожалению, неправильное написание";
}
?>

Добавить

Примечания пользователей 3 notes

up
0
si at youbeenx dot com
19 years ago
I felt that it would help to expand on batch spell checking using this function. The previously posted example implodes using spaces as the separator for each word. There are however situations in which doing this will not return the desired result. For example, "Hello, I like coding." will return an array with two problems, "Hello," and "coding.", both these words are spelt correctly, but pspell_check() will deem them as spelled incorrectly because a comma or a period is being passed in to the function along with the word. The following example allows you to extract only the words (using regular expressions to ignore grammar such as periods or commas) in to an array and then add in html font tags to highlight all words spelled incorrectly red before returning the string.

<?

Function SpellCheck($string) {

$pspell_link = pspell_new("en");
preg_match_all("/[A-Z\']{1,16}/i", $string, $words);

for ($i = 0; $i < count($words[0]); $i++) {

if (!pspell_check($pspell_link, $words[0][$i])) {

$string = str_replace($words[0][$i], "<font color=\"#FF0000\">" . $words[0][$i] . "</font>", $string);

}

}

return $string;

}

?>
up
-3
digit6 at gmail dot com
7 years ago
A better pattern for splitting the words of a query up is:

preg_match_all('/[^\w\']/+/', $query, $word)
// $words has the words.
up
-4
Jcart
19 years ago
<?php

//should be using explode instead of implode
//$word = implode(" ", $message);
$word = explode(" ", $message);
foreach(
$word as $k => $v) {
if (
pspell_check($pspell_link, $v)) {
echo
"spelled right";
} else {
echo
"Sorry, wrong spelling";
};
};

?>
To Top