PHP 8.5.0 Alpha 1 available for testing

pspell_new

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

pspell_newCarga un nuevo diccionario

Descripción

pspell_new(
    string $language,
    string $spelling = "",
    string $jargon = "",
    string $encoding = "",
    int $mode = 0
): PSpell\Dictionary|false

pspell_new() abre un nuevo diccionario y devuelve una instancia de PSpell\Dictionary, para ser utilizada con otras funciones pspell.

Para más información y ejemplos, consúltese el sitio » http://aspell.net/.

Parámetros

language

El argumento de idioma spelling se compone de las dos letras del código de idioma ISO 639, y del código opcional de país ISO 3166, separados por un '_'.

spelling

Este argumento es necesario para los idiomas que tienen más de una ortografía, como el inglés o el francés. Los valores reconocidos son 'american', 'british', y 'canadian'.

jargon

El argumento jargon contiene información adicional para distinguir dos listas de palabras que tienen el mismo marcado de idioma y ortografía.

encoding

El argumento encoding es el tipo de codificación de las palabras. Los valores válidos son 'utf-8', 'iso8859-*', 'koi8-r', 'viscii', 'cp1252', 'machine unsigned 16', 'machine unsigned 32'. Este argumento no ha sido probado de forma exhaustiva, por lo que se recomienda precaución al utilizarlo.

mode

El argumento mode es el modo de funcionamiento del corrector ortográfico. Varios modos están disponibles :

mode es una máscara construida a partir de las constantes listadas anteriormente. Sin embargo, PSPELL_FAST, PSPELL_NORMAL y PSPELL_BAD_SPELLERS son mutuamente excluyentes : no se deben utilizar a la vez.

Valores devueltos

Devuelve una instancia de PSpell\Dictionary en caso de éxito, o false en caso de error.

Historial de cambios

Versión Descripción
8.1.0 Ahora devuelve una instancia de PSpell\Dictionary ; anteriormente se devolvía un recurso.

Ejemplos

Ejemplo #1 pspell_new()

<?php
$pspell
= pspell_new("en", "", "", "",
(
PSPELL_FAST|PSPELL_RUN_TOGETHER));
?>

add a note

User Contributed Notes 2 notes

up
11
wookie
16 years ago
Just as a small tip, I noticed that when you call pspell_new multiple times, php does not free memory usage when the resource is destroyed, but only when your entire script has completely finished. So if you create a pspell_link resource and you intend to use it again somewhere else, instead of calling pspell_new again, keep track of your original pspell_link resource instantiation, and use it again, your script will run much more efficiently.

I was switching between 16 dictionaries by just calling a new pspell_new everytime, my memory usage on the server grew until i hit a failure/php core dump. :-/ So i stored each pspell resource in an array keyed by language, and checked if the resource existed first, before creating one if needed.

I hope that helps someone.
up
1
allan at wagawaga dot dk
16 years ago
I think the language and spelling parameters differs on different PHP versions and/or aspell/UNIX distributions.

My PHP 5.2.6 Debian ignores the spelling parameter.

Instead:

For Americans use en_US as language.
For British use en_GB (not en_UK)
For Canadian use en_CA
To Top