Ref/pspell-Phpdoc专题
pspell_add_to_personal
Add the word to a personal wordlist
说明
bool <span
class="methodname">pspell_add_to_personal ( <span
class="methodparam">int $dictionary ,
string
$word )
pspell_add_to_personal adds a word to the personal wordlist. If you used <span class="function">pspell_new_config with <span class="function">pspell_config_personal to open the dictionary, you can save the wordlist later with <span class="function">pspell_save_wordlist.
参数
dictionary
word
The added word.
返回值
成功时返回 true, 或者在失败时返回 false。
范例
示例 #1 pspell_add_to_personal
<?php
$pspell_config = pspell_config_create("en");
pspell_config_personal($pspell_config, "/var/dictionaries/custom.pws");
$pspell_link = pspell_new_config($pspell_config);
pspell_add_to_personal($pspell_link, "Vlad");
pspell_save_wordlist($pspell_link);
?>
注释
Note:
This function will not work unless you have pspell .11.2 and aspell .32.5 or later.
pspell_add_to_session
Add the word to the wordlist in the current session
说明
bool <span
class="methodname">pspell_add_to_session ( <span
class="methodparam">int $dictionary ,
string
$word )
pspell_add_to_session adds a word to the wordlist associated with the current session. It is very similar to pspell_add_to_personal
参数
dictionary
word
The added word.
返回值
成功时返回 true, 或者在失败时返回 false。
pspell_check
Check a word
说明
bool <span
class="methodname">pspell_check ( <span
class="methodparam">int $dictionary ,
string
$word )
pspell_check checks the spelling of a word.
参数
dictionary
word
The tested word.
返回值
Returns true if the spelling is correct, false if not.
范例
示例 #1 pspell_check Example
<?php
$pspell_link = pspell_new("en");
if (pspell_check($pspell_link, "testt")) {
echo "This is a valid spelling";
} else {
echo "Sorry, wrong spelling";
}
?>
pspell_clear_session
Clear the current session
说明
bool <span
class="methodname">pspell_clear_session ( <span
class="methodparam">int $dictionary )
pspell_clear_session clears the current session. The current wordlist becomes blank, and, for example, if you try to save it with <span class="function">pspell_save_wordlist, nothing happens.
参数
dictionary
返回值
成功时返回 true, 或者在失败时返回 false。
范例
示例 #1 pspell_add_to_personal Example
<?php
$pspell_config = pspell_config_create("en");
pspell_config_personal($pspell_config, "/var/dictionaries/custom.pws");
$pspell_link = pspell_new_config($pspell_config);
pspell_add_to_personal($pspell_link, "Vlad");
pspell_clear_session($pspell_link);
pspell_save_wordlist($pspell_link); //"Vlad" will not be saved
?>
pspell_config_create
Create a config used to open a dictionary
说明
int <span
class="methodname">pspell_config_create ( <span
class="methodparam">string $language
[, string
$spelling = "" [, <span
class="methodparam">string $jargon<span
class="initializer"> = "" [, <span
class="methodparam">string $encoding<span
class="initializer"> = "" ]]] )
Create a config used to open a dictionary.
pspell_config_create has a very similar syntax to pspell_new. In fact, using pspell_config_create immediately followed by pspell_new_config will produce the exact same result. However, after creating a new config, you can also use pspell_config_* functions before calling pspell_new_config to take advantage of some advanced functionality.
For more information and examples, check out inline manual pspell website:» http://aspell.net/.
参数
language
The language parameter is the language code which consists of the two
letter ISO 639 language code and an optional two letter ISO 3166 country
code after a dash or underscore.
spelling
The spelling parameter is the requested spelling for languages with more
than one spelling such as English. Known values are 'american',
'british', and 'canadian'.
jargon
The jargon parameter contains extra information to distinguish two
different words lists that have the same language and spelling
parameters.
encoding
The encoding parameter is the encoding that words are expected to be in.
Valid values are 'utf-8', 'iso8859-*', 'koi8-r', 'viscii', 'cp1252',
'machine unsigned 16', 'machine unsigned 32'. This parameter is largely
untested, so be careful when using.
返回值
Returns a pspell config identifier, or false on error.
范例
示例 #1 pspell_config_create
<?php
$pspell_config = pspell_config_create("en");
pspell_config_personal($pspell_config, "/var/dictionaries/custom.pws");
pspell_config_repl($pspell_config, "/var/dictionaries/custom.repl");
$pspell_link = pspell_new_personal($pspell_config, "en");
?>
pspell_config_data_dir
Location of language data files
说明
bool <span
class="methodname">pspell_config_data_dir ( <span
class="methodparam">int $config ,
string
$directory )
Warning
本函数还未编写文档,仅有参数列表。
返回值
成功时返回 true, 或者在失败时返回 false。
pspell_config_dict_dir
Location of the main word list
说明
bool <span
class="methodname">pspell_config_dict_dir ( <span
class="methodparam">int $config ,
string
$directory )
Warning
本函数还未编写文档,仅有参数列表。
返回值
成功时返回 true, 或者在失败时返回 false。
pspell_config_ignore
Ignore words less than N characters long
说明
bool <span
class="methodname">pspell_config_ignore ( <span
class="methodparam">int $config ,
int
$min_length )
pspell_config_ignore should be used on a config before calling pspell_new_config. This function allows short words to be skipped by the spell checker.
参数
config
min_length
Words less than min_length characters will be skipped.
返回值
成功时返回 true, 或者在失败时返回 false。
范例
示例 #1 pspell_config_ignore
<?php
$pspell_config = pspell_config_create("en");
pspell_config_ignore($pspell_config, 5);
$pspell_link = pspell_new_config($pspell_config);
pspell_check($pspell_link, "abcd"); //will not result in an error
?>
pspell_config_mode
Change the mode number of suggestions returned
说明
bool <span
class="methodname">pspell_config_mode ( <span
class="methodparam">int $config ,
int $mode )
pspell_config_mode should be used on a config before calling pspell_new_config. This function determines how many suggestions will be returned by <span class="function">pspell_suggest.
参数
config
mode
The mode parameter is the mode in which spellchecker will work. There
are several modes available:
-
PSPELL_FAST- Fast mode (least number of suggestions) -
PSPELL_NORMAL- Normal mode (more suggestions) -
PSPELL_BAD_SPELLERS- Slow mode (a lot of suggestions)
返回值
成功时返回 true, 或者在失败时返回 false。
范例
示例 #1 pspell_config_mode Example
<?php
$pspell_config = pspell_config_create("en");
pspell_config_mode($pspell_config, PSPELL_FAST);
$pspell_link = pspell_new_config($pspell_config);
pspell_check($pspell_link, "thecat");
?>
pspell_config_personal
Set a file that contains personal wordlist
说明
bool <span
class="methodname">pspell_config_personal ( <span
class="methodparam">int $config ,
string
$filename )
Set a file that contains personal wordlist. The personal wordlist will be loaded and used in addition to the standard one after you call <span class="function">pspell_new_config. The file is also the file where pspell_save_wordlist will save personal wordlist to.
pspell_config_personal should be used on a config before calling <span class="function">pspell_new_config.
参数
config
filename
The personal wordlist. If the file does not exist, it will be created.
The file should be writable by whoever PHP runs as (e.g. nobody).
返回值
成功时返回 true, 或者在失败时返回 false。
范例
示例 #1 pspell_config_personal
<?php
$pspell_config = pspell_config_create("en");
pspell_config_personal($pspell_config, "/var/dictionaries/custom.pws");
$pspell_link = pspell_new_config($pspell_config);
pspell_check($pspell_link, "thecat");
?>
注释
Note:
This function will not work unless you have pspell .11.2 and aspell .32.5 or later.
pspell_config_repl
Set a file that contains replacement pairs
说明
bool <span
class="methodname">pspell_config_repl ( <span
class="methodparam">int $config ,
string
$filename )
Set a file that contains replacement pairs.
The replacement pairs improve the quality of the spellchecker. When a word is misspelled, and a proper suggestion was not found in the list, pspell_store_replacement can be used to store a replacement pair and then <span class="function">pspell_save_wordlist to save the wordlist along with the replacement pairs.
pspell_config_repl should be used on a config before calling pspell_new_config.
参数
config
filename
The file should be writable by whoever PHP runs as (e.g. nobody).
返回值
成功时返回 true, 或者在失败时返回 false。
范例
示例 #1 pspell_config_repl
<?php
$pspell_config = pspell_config_create("en");
pspell_config_personal($pspell_config, "/var/dictionaries/custom.pws");
pspell_config_repl($pspell_config, "/var/dictionaries/custom.repl");
$pspell_link = pspell_new_config($pspell_config);
pspell_check($pspell_link, "thecat");
?>
注释
Note:
This function will not work unless you have pspell .11.2 and aspell .32.5 or later.
pspell_config_runtogether
Consider run-together words as valid compounds
说明
bool <span
class="methodname">pspell_config_runtogether ( <span
class="methodparam">int $config ,
bool $allow
)
This function determines whether run-together words will be treated as legal compounds. That is, "thecat" will be a legal compound, although there should be a space between the two words. Changing this setting only affects the results returned by <span class="function">pspell_check; <span class="function">pspell_suggest will still return suggestions.
pspell_config_runtogether should be used on a config before calling <span class="function">pspell_new_config.
参数
config
allow
true if run-together words should be treated as legal compounds,
false otherwise.
返回值
成功时返回 true, 或者在失败时返回 false。
范例
示例 #1 pspell_config_runtogether
<?php
$pspell_config = pspell_config_create("en");
pspell_config_runtogether($pspell_config, true);
$pspell_link = pspell_new_config($pspell_config);
pspell_check($pspell_link, "thecat");
?>
pspell_config_save_repl
Determine whether to save a replacement pairs list along with the wordlist
说明
bool <span
class="methodname">pspell_config_save_repl ( <span
class="methodparam">int $config ,
bool $save
)
pspell_config_save_repl determines whether pspell_save_wordlist will save the replacement pairs along with the wordlist. Usually there is no need to use this function because if <span class="function">pspell_config_repl is used, the replacement pairs will be saved by <span class="function">pspell_save_wordlist anyway, and if it is not, the replacement pairs will not be saved.
pspell_config_save_repl should be used on a config before calling <span class="function">pspell_new_config.
参数
config
save
true if replacement pairs should be saved, false otherwise.
返回值
成功时返回 true, 或者在失败时返回 false。
注释
Note:
This function will not work unless you have pspell .11.2 and aspell .32.5 or later.
pspell_new_config
Load a new dictionary with settings based on a given config
说明
int<span
class="type">false <span
class="methodname">pspell_new_config ( <span
class="methodparam">int $config )
pspell_new_config opens up a new dictionary with settings specified in a config, created with <span class="function">pspell_config_create and modified with <span class="function">pspell_config_* functions. This method provides you with the most flexibility and has all the functionality provided by pspell_new and <span class="function">pspell_new_personal.
参数
config
The config parameter is the one returned by <span
class="function">pspell_config_create when the config was
created.
返回值
Returns a dictionary link identifier on success, 或者在失败时返回
false.
范例
示例 #1 pspell_new_config
<?php
$pspell_config = pspell_config_create("en");
pspell_config_personal($pspell_config, "/var/dictionaries/custom.pws");
pspell_config_repl($pspell_config, "/var/dictionaries/custom.repl");
$pspell_link = pspell_new_config($pspell_config);
?>
pspell_new_personal
Load a new dictionary with personal wordlist
说明
int<span
class="type">false <span
class="methodname">pspell_new_personal ( <span
class="methodparam">string $filename
, string
$language [, <span
class="type">string $spelling =
"" [, <span
class="type">string $jargon =
"" [, <span
class="type">string $encoding =
"" [, <span
class="type">int $mode =
0 ]]]] )
pspell_new_personal opens up a new dictionary with a personal wordlist. The wordlist can be modified and saved with pspell_save_wordlist, if desired. However, the replacement pairs are not saved. In order to save replacement pairs, you should create a config using <span class="function">pspell_config_create, set the personal wordlist file with <span class="function">pspell_config_personal, set the file for replacement pairs with <span class="function">pspell_config_repl, and open a new dictionary with pspell_new_config.
For more information and examples, check out inline manual pspell website:» http://aspell.net/.
参数
filename
The file where words added to the personal list will be stored. It
should be an absolute filename beginning with '/' because otherwise it
will be relative to $HOME, which is "/root" for most systems, and is
probably not what you want.
language
The language code which consists of the two letter ISO 639 language code
and an optional two letter ISO 3166 country code after a dash or
underscore.
spelling
The requested spelling for languages with more than one spelling such as
English. Known values are 'american', 'british', and 'canadian'.
jargon
Extra information to distinguish two different words lists that have the
same language and spelling parameters.
encoding
The encoding that words are expected to be in. Valid values are utf-8,
iso8859-*, koi8-r, viscii, cp1252, machine unsigned 16,
machine unsigned 32.
mode
The mode in which spellchecker will work. There are several modes
available:
-
PSPELL_FAST- Fast mode (least number of suggestions) -
PSPELL_NORMAL- Normal mode (more suggestions) -
PSPELL_BAD_SPELLERS- Slow mode (a lot of suggestions) -
PSPELL_RUN_TOGETHER- Consider run-together words as legal compounds. That is, "thecat" will be a legal compound, although there should be a space between the two words. Changing this setting only affects the results returned by pspell_check; <span class="function">pspell_suggest will still return suggestions.
Mode is a bitmask constructed from different constants listed above.
However, PSPELL_FAST, PSPELL_NORMAL and
PSPELL_BAD_SPELLERS are mutually exclusive, so you should select
only one of them.
返回值
Returns the dictionary link identifier for use in other pspell functions.
范例
示例 #1 pspell_new_personal
<?php
$pspell_link = pspell_new_personal ("/var/dictionaries/custom.pws",
"en", "", "", "", PSPELL_FAST|PSPELL_RUN_TOGETHER);
?>
pspell_new
Load a new dictionary
说明
int<span
class="type">false <span
class="methodname">pspell_new ( <span
class="type">string $language [, <span
class="methodparam">string $spelling<span
class="initializer"> = "" [, <span
class="methodparam">string $jargon<span
class="initializer"> = "" [, <span
class="methodparam">string $encoding<span
class="initializer"> = "" [, <span
class="methodparam">int $mode<span
class="initializer"> = 0 ]]]] )
pspell_new opens up a new dictionary and returns the dictionary link identifier for use in other pspell functions.
For more information and examples, check out inline manual pspell website:» http://aspell.net/.
参数
language
The language parameter is the language code which consists of the two
letter ISO 639 language code and an optional two letter ISO 3166 country
code after a dash or underscore.
spelling
The spelling parameter is the requested spelling for languages with more
than one spelling such as English. Known values are 'american',
'british', and 'canadian'.
jargon
The jargon parameter contains extra information to distinguish two
different words lists that have the same language and spelling
parameters.
encoding
The encoding parameter is the encoding that words are expected to be in.
Valid values are 'utf-8', 'iso8859-*', 'koi8-r', 'viscii', 'cp1252',
'machine unsigned 16', 'machine unsigned 32'. This parameter is largely
untested, so be careful when using.
mode
The mode parameter is the mode in which spellchecker will work. There
are several modes available:
-
PSPELL_FAST- Fast mode (least number of suggestions) -
PSPELL_NORMAL- Normal mode (more suggestions) -
PSPELL_BAD_SPELLERS- Slow mode (a lot of suggestions) -
PSPELL_RUN_TOGETHER- Consider run-together words as legal compounds. That is, "thecat" will be a legal compound, although there should be a space between the two words. Changing this setting only affects the results returned by pspell_check; <span class="function">pspell_suggest will still return suggestions.
Mode is a bitmask constructed from different constants listed above.
However, PSPELL_FAST, PSPELL_NORMAL and
PSPELL_BAD_SPELLERS are mutually exclusive, so you should select
only one of them.
返回值
Returns the dictionary link identifier on success 或者在失败时返回
false.
范例
示例 #1 pspell_new
<?php
$pspell_link = pspell_new("en", "", "", "",
(PSPELL_FAST|PSPELL_RUN_TOGETHER));
?>
pspell_save_wordlist
Save the personal wordlist to a file
说明
bool <span
class="methodname">pspell_save_wordlist ( <span
class="methodparam">int $dictionary )
pspell_save_wordlist saves the personal wordlist from the current session. The location of files to be saved specified with pspell_config_personal and (optionally) pspell_config_repl.
参数
dictionary
A dictionary link identifier opened with <span
class="function">pspell_new_personal.
返回值
成功时返回 true, 或者在失败时返回 false。
范例
示例 #1 pspell_add_to_personal
<?php
$pspell_config = pspell_config_create("en");
pspell_config_personal($pspell_config, "/tmp/dicts/newdict");
$pspell_link = pspell_new_config($pspell_config);
pspell_add_to_personal($pspell_link, "Vlad");
pspell_save_wordlist($pspell_link);
?>
注释
Note:
This function will not work unless you have pspell .11.2 and aspell .32.5 or later.
pspell_store_replacement
Store a replacement pair for a word
说明
bool <span
class="methodname">pspell_store_replacement ( <span
class="methodparam">int $dictionary ,
string
$misspelled , <span
class="type">string $correct )
pspell_store_replacement stores a replacement pair for a word, so that replacement can be returned by pspell_suggest later. In order to be able to take advantage of this function, you have to use <span class="function">pspell_new_personal to open the dictionary. In order to permanently save the replacement pair, you have to use <span class="function">pspell_config_personal and <span class="function">pspell_config_repl to set the path where to save your custom wordlists, and then use <span class="function">pspell_save_wordlist for the changes to be written to disk.
参数
dictionary
A dictionary link identifier, opened with <span
class="function">pspell_new_personal
misspelled
The misspelled word.
correct
The fixed spelling for the misspelled word.
返回值
成功时返回 true, 或者在失败时返回 false。
范例
示例 #1 pspell_store_replacement
<?php
$pspell_config = pspell_config_create("en");
pspell_config_personal($pspell_config, "/var/dictionaries/custom.pws");
pspell_config_repl($pspell_config, "/var/dictionaries/custom.repl");
$pspell_link = pspell_new_config($pspell_config);
pspell_store_replacement($pspell_link, $misspelled, $correct);
pspell_save_wordlist($pspell_link);
?>
注释
Note:
This function will not work unless you have pspell .11.2 and aspell .32.5 or later.
pspell_suggest
Suggest spellings of a word
说明
array<span
class="type">false <span
class="methodname">pspell_suggest ( <span
class="methodparam">int $dictionary ,
string
$word )
pspell_suggest returns an array of possible spellings for the given word.
参数
dictionary
word
The tested word.
返回值
Returns an array of possible spellings.
范例
示例 #1 pspell_suggest example
<?php
$pspell_link = pspell_new("en");
if (!pspell_check($pspell_link, "testt")) {
$suggestions = pspell_suggest($pspell_link, "testt");
foreach ($suggestions as $suggestion) {
echo "Possible spelling: $suggestion<br />";
}
}
?>
目录
- pspell_add_to_personal — Add the word to a personal wordlist
- pspell_add_to_session — Add the word to the wordlist in the current session
- pspell_check — Check a word
- pspell_clear_session — Clear the current session
- pspell_config_create — Create a config used to open a dictionary
- pspell_config_data_dir — Location of language data files
- pspell_config_dict_dir — Location of the main word list
- pspell_config_ignore — Ignore words less than N characters long
- pspell_config_mode — Change the mode number of suggestions returned
- pspell_config_personal — Set a file that contains personal wordlist
- pspell_config_repl — Set a file that contains replacement pairs
- pspell_config_runtogether — Consider run-together words as valid compounds
- pspell_config_save_repl — Determine whether to save a replacement pairs list along with the wordlist
- pspell_new_config — Load a new dictionary with settings based on a given config
- pspell_new_personal — Load a new dictionary with personal wordlist
- pspell_new — Load a new dictionary
- pspell_save_wordlist — Save the personal wordlist to a file
- pspell_store_replacement — Store a replacement pair for a word
- pspell_suggest — Suggest spellings of a word