21,893
社区成员




<?php
class getCom //采用单例模式来说创建WS分词COM组件对象
{
private static $getcom; //定义一个静态的getCom的对象变量
public static $ws; //定义一个静态的WS分词COM的对象变量
private function __construct() //构造函数,通过getCom的构造函数,新建一个WS COM对象ws
{
self::$ws = new COM("WS.com") or die("不能链接到WS组件!");
}
public static function getComInstance() //静态方法,保证只有一个getCom的对象getcom
{
if(self::$getcom == null)
{
self::$getcom = new getCom();
}
return self::$getcom;
}
public function getWS() //返回WS COM对象变量ws
{
return self::$ws;
}
}
?>
<?php
include("getCom.php"); //包含getCom类文件
$com = getCom::getComInstance(); //获得类getCom的一个对象
$ws = $com->getWS(); //获得getcom对象的ws分词com组件对象变量
$type = $_POST['radioButton']; //获得radio的对象值
$inputStr = $_POST['inputString']; //获得文本域的输入值
$pathCur = getcwd(); //获取文件路径
$pathDir= "\\WS\\";
$path = $pathCur.$pathDir;
$ws->SetPath($path); //设置路径
$ws->InitWS(); //WS进行初始化
$outputStr = $ws->Segment($type,$inputStr); //调用分词函数
echo $outputStr; //显示分词结果
?>