<?php // Plug-in 89: Words From Root
// This is an executable example with additional code supplied
// To obtain just the plug-ins please click on the Download link
if (!isset($_GET['word']))
exit;
$result = PIPHP_WordsFromRoot($_GET['word'],
'dictionary.txt', 20);
if ($result != FALSE)
foreach ($result as $word)
echo "$word<br />";
function PIPHP_WordsFromRoot($word, $filename, $max)
{
// Plug-in 89: Words From Root
//
// This plug-in takes a word or word part and then returns
// an array of all the words in the word file that begin
// with the supplied word. It requires these arguments:
//
// $word: A word to look up
// $dictionary: The location of a list of words separated
// by non-word or space characters such as
// \n or \r\n
$dict = file_get_contents($filename);
preg_match_all('/' . $word . '[\w ]+/', $dict, $matches);
$c = min(count($matches[0]), $max);
$out = array();
for ($j = 0 ; $j < $c ; ++$j) $out[$j] = $matches[0][$j];
return $out;
}
?>
插件说明:
插件89接受一个单词的几个首字母,返回字典中所有以这些字母开头的单词或短语。它需要以下参数:
$word 词根
$filename 字典文件的路径
$max 返回单词或短语的最大个数