这是一段用来分词并进行词性匹配的程序段,其中数据库表cixing有word和cx两个字段,用的是PHP+APACH+MYSQL
为什么有时候运行很慢,有时候又可以,关系到毕业设计,先谢谢各位大侠了 $temp="唐朝的皇帝是谁"; $str_len=strlen($temp);//输入字符串的总长度
if($str_len!=0)//若字符串不为空
{
$str=array();//初始化一个数组
$pos=0;//当前位置
$len=2;
$att_str=array();//初始化一个数组
while($pos<$str_len)
{
$str_tmp=substr($temp,$pos,$len);//取第一个字“唐” //到数据库查询$str_tmp $hd=mysql_connect($server_hostname,$server_username,$server_password) ;
$dbname=mysql_select_db("history",$hd);
$query="select * from cixing where word='$str_tmp' ";
$result=mysql_query($query);
mysql_close($hd);
$re=mysql_fetch_row($result); if($re[0]==$str_tmp){ $Word=$re[0]; //返回单词
$Cixing=$re[1]; //返回词性 $pos=$pos+strlen($str_tmp);
$len=2; array_push($str,$Word,$Cixing);//将单词和词性入栈$str echo "<br>";
$i++;
$j++;
}
else{ $len=$len+2;
}
为什么有时候运行很慢,有时候又可以,关系到毕业设计,先谢谢各位大侠了 $temp="唐朝的皇帝是谁"; $str_len=strlen($temp);//输入字符串的总长度
if($str_len!=0)//若字符串不为空
{
$str=array();//初始化一个数组
$pos=0;//当前位置
$len=2;
$att_str=array();//初始化一个数组
while($pos<$str_len)
{
$str_tmp=substr($temp,$pos,$len);//取第一个字“唐” //到数据库查询$str_tmp $hd=mysql_connect($server_hostname,$server_username,$server_password) ;
$dbname=mysql_select_db("history",$hd);
$query="select * from cixing where word='$str_tmp' ";
$result=mysql_query($query);
mysql_close($hd);
$re=mysql_fetch_row($result); if($re[0]==$str_tmp){ $Word=$re[0]; //返回单词
$Cixing=$re[1]; //返回词性 $pos=$pos+strlen($str_tmp);
$len=2; array_push($str,$Word,$Cixing);//将单词和词性入栈$str echo "<br>";
$i++;
$j++;
}
else{ $len=$len+2;
}
$len=2;
$att_str=array();//初始化一个数组
while($pos<$str_len) //死循环
=======================
static $pos=0;//当前位置
$len=2;
$att_str=array();//初始化一个数组
while($pos<$str_len)
========================================