插件89:词根提示

<?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 返回单词或短语的最大个数

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值