官方文檔:http://es.php.net/manual/en/book.enchant.php
示常式序:
<?php
$broker = enchant_broker_init();
$dictionaries = enchant_broker_list_dicts($broker);
echo "This server provides the following dictionaries:<br>";
$ar = array();
foreach ($dictionaries as $dictionary) {
array_push($ar, $dictionary["lang_tag"]);
}
echo join(",", $ar);
echo "<hr>";
$words = array("calender", "roll", "specially", "hasband", "stuff", "staff", "hablar", "carbeza", "dolor", "tengo", "tener", "ser", "estoy", "de", "muchacha", "mucho", "llamo", "kilo", "infinitivo", "cultura", "nada", "cama", "hasta", "papa", "mama", "lentes", "leche", "idioma", "finito", "usted", "ustedes", "yo", "ella", "nosotros", "vosotros", "ellos", "ellas", "contamos", "connex", "connection", "disambigration", "somos", "days", "domingo", "lunes", "vertes", "enero", "septiembre", "octubre", "noviember", "paitent", "september", "November", "January", "April", "abril", "timid");
$languages = array("en_US", "es");
foreach ($languages as $language) {
echo "<h3>For $language:</h3>";
if (enchant_broker_dict_exists($broker, $language)) {
$dictionary = enchant_broker_request_dict($broker, $language);
foreach ($words as $word) {
if (enchant_dict_check($dictionary, $word)) {
echo "Word '$word' is spelled correctly.<br>";
} else {
echo "<b>Word '$word' is spelled incorrectly.</b><br>";
$suggestions = enchant_dict_suggest($dictionary, $word);
echo "<span style=\"color:green\">" . join(", ", $suggestions) . "</span><br>";
}
}
enchant_broker_free_dict($dictionary);
} else {
echo "Dictionary '$language' doesn't exist.<br>";
}
}
enchant_broker_free($broker);
?>
運行結果:
This server provides the following dictionaries:
en_USFor en_US:Word 'calender' is spelled incorrectly.
calendar, ca lender, ca-lender, lender, candler, Calder, caldera
Word 'roll' is spelled correctly.
Word 'specially' is spelled correctly.
Word 'hasband' is spelled incorrectly.
hatband, husband, has band, has-band, hairband
Word 'stuff' is spelled correctly.
Word 'staff' is spelled correctly.
Word 'hablar' is spelled incorrectly.
Harlan
Word 'carbeza' is spelled incorrectly.
carbide
Word 'dolor' is spelled correctly.
Word 'tengo' is spelled incorrectly.
tango, ten go, ten-go, gotten
Word 'tener' is spelled incorrectly.
tenet, tenser, tenner, tender, enter, tenor, toner, tuner, ten er, ten-er, terrine, tern
Word 'ser' is spelled incorrectly.
tier, res, see, set, er, sere, seer, sear, user, serf, sir, sea, sen, sec, per
Word 'estoy' is spelled incorrectly.
es toy, es-toy, Tolstoy
Word 'de' is spelled incorrectly.
DE, ed, d, e, die, den, doe, ode, due, deg, deb, dye, def, dew, re
Word 'muchacha' is spelled incorrectly.
Duchamp
Word 'mucho' is spelled incorrectly.
much, macho, much o, mucous
Word 'llamo' is spelled incorrectly.
llano, llama, Alamo
Word 'kilo' is spelled correctly.
Word 'infinitivo' is spelled incorrectly.
infinitive, infinitival
Word 'cultura' is spelled incorrectly.
cultural, culture
Word 'nada' is spelled incorrectly.
Dada, Canada, Adana, Adan
Word 'cama' is spelled incorrectly.
cams, cam, came, coma, lama, mama, camp, Rama, Gama, Kama, ca ma, ca-ma, cam a, CAM
Word 'hasta' is spelled incorrectly.
hast, Shasta, haste, pasta, hasty, has ta, has-ta, hast a, Tasha, stash
Word 'papa' is spelled correctly.
Word 'mama' is spelled correctly.
Word 'lentes' is spelled incorrectly.
lenses, lent es, lent-es, Lents, gentles, tentacles, lent
Word 'leche' is spelled incorrectly.
lech, leches, lecher, leched, leech, lech e, heckle
Word 'idioma' is spelled incorrectly.
idioms, idiom, idiom a
Word 'finito' is spelled incorrectly.
finite
Word 'usted' is spelled incorrectly.
used, rusted, ousted, lusted, dusted, gusted, busted, us ted, us-ted, tested, stetted, steed
Word 'ustedes' is spelled incorrectly.
tested
Word 'yo' is spelled correctly.
Word 'ella' is spelled incorrectly.
Ella, ells, ell, fella, Della, Bella, ell a
Word 'nosotros' is spelled incorrectly.
nostrils
Word 'vosotros' is spelled incorrectly.
provosts
Word 'ellos' is spelled incorrectly.
ells, cellos, hellos, ell's, jellos
Word 'ellas' is spelled incorrectly.
ells, fellas, ell's, ell as, ell-as, paellas, Ascella, Ella, Aspell
Word 'contamos' is spelled incorrectly.
contaminants
Word 'connex' is spelled incorrectly.
conned, convex, cone
Word 'connection' is spelled correctly.
Word 'disambigration' is spelled incorrectly.
disambiguation, disintegration
Word 'somos' is spelled incorrectly.
solos, homos, so mos, so-mos, bosom
Word 'days' is spelled correctly.
Word 'domingo' is spelled incorrectly.
Domingo, doming, domino, dooming, doming o
Word 'lunes' is spelled incorrectly.
lines, lubes, lunges, lanes, lures, runes, lutes, tunes, dunes, lungs, luges, lunches
Word 'vertes' is spelled incorrectly.
verses, verges, vertexes, vertices
Word 'enero' is spelled incorrectly.
Nero
Word 'septiembre' is spelled incorrectly.
September
Word 'octubre' is spelled incorrectly.
October
Word 'noviember' is spelled incorrectly.
November, nonmember
Word 'paitent' is spelled incorrectly.
patient, patent, penitent, painted, painter, paint
Word 'september' is spelled incorrectly.
September
Word 'November' is spelled correctly.
Word 'January' is spelled correctly.
Word 'April' is spelled correctly.
Word 'abril' is spelled incorrectly.
brill
Word 'timid' is spelled correctly.
For es:Dictionary 'es' doesn't exist.