function string2words($s,$return_string = true,$encode64 = true)
{
$re = '';
//匹配汉字
if (preg_match_all("/([x{4e00}-x{9fff}]{2,})/u",$s,$ms))
{
foreach($ms[0] as $w)
{
//关键部分:分词
$l = strlen($w)/3;
for($i=0;$i<$l;$i++)
{
$wi = substr($w,$i*3,6);
if (strlen($wi) > 3)
{
$re .= ($encode64)?' '.str_replace(',','@',base64_encode($wi)):' '.$wi;
}
}
}
}
//匹配数字
if (preg_match_all("/(d+[.]?d+)/",$s,$ms))
{
foreach($ms[0] as $wi)
{
if(strlen($wi) >= 2)
{
$re .= ($encode64)?' '.str_replace(',','@',base64_encode($wi)):' '.$wi;
}
}
$s = preg_replace("/(d+[.]?d+)/",' ',$s);
}
//去掉所有双字节字符
$s = preg_replace("/([^x{00}-x{ff}]+)/u",' ',$s);
$re = $s.' '.$re;
if (!$return_string)
{
$re = preg_replace("/([^d])([,.-?n])([^d])/",'$1 $3',$re);
$re = trim(preg_replace("/[s]{2,}/",' ',$re));
$arr = explode(' ',$re);
$re = array();
foreach($arr as $a)
{
if (strlen($a) >= 2) $re[] = $a;
}
return $re;
}
else
{
$re = trim(preg_replace("/[s,.]{2,}/",' ',$re));
return $re;
}
}
完。


Flash Player文件
