<?php /* * 摘 要: 分词工具使用演示 * 注 释:本工具中文分词速度略慢,但是使用方便 * 作 者: 刘海艇 * 修改日期: 2013-06-27 */ require_once "index.php"; header("content-type:text/html;charset=utf-8"); $str = "你叫什么名字啊,哈哈"; $start_time = microtime(true); //--------------------------------- print_r(splitWords($str)); //------------------------------------ $end_time = microtime(true); echo '耗时' . round($end_time - $start_time, 3) . '秒';
function getNameFromPath ($fileName) { $fileName = basename($fileName); if (strrpos($fileName, '/') !== FALSE) $fileName = strrchr($fileName, '/'); if (strrpos($fileName, '.') !== FALSE) $fileName = substr($fileName, 0, strrpos($fileName, '.')); return splitWords($fileName); }
while ($row = $db->fetch_assoc($result)) { $user[] = $row['name']; } $request = implode(',', $gpc->prepare($user)); echo $request; } else { echo 8; } } elseif ($action == 'search') { $search = $gpc->get('search', str); if (strlen($search) > 2) { $search = urldecode($search); $search = preg_replace("/(\\s){1,}/is", " ", $search); $search = preg_replace("/\\*{1,}/is", '*', $search); $ignorewords = $lang->get_words(); $searchwords = splitWords($search); $ignored = array(); foreach ($searchwords as $sw) { $sw = trim($sw); if ($sw[0] == '-') { $sw2 = substr($sw, 1); } else { $sw2 = $sw; } $sw2 = str_replace('*', '', $sw2); if (in_array(strtolower($sw2), $ignorewords) || strxlen($sw2) < $config['searchminlength']) { $ignored[] = $sw2; } } if (count($ignored) > 0) { echo implode(',', $ignored);
function split() { $str = $_POST['words']; include_once C('WX_PATH') . 'handle/modules/splitwords/index.php'; $result = ''; if (!empty($str)) { $arr = splitWords($str); foreach ($arr as $k => $v) { $result .= '<span onclick="fill_keys(this)">' . $v . '</span>'; } $this->ajaxReturn('1', $result, 1); } else { $this->ajaxReturn('0', '', 0); } }