第1个回答 2011-12-06
按你的需求写了一个:
<?php
//只支持GB2312
header('Content-type:text/html;charset=GB2312');
$str = "大家好 今天天气好啊 在干么啊 没干什么啊";
$arr = split(' ', $str);
print_r($arr);
foreach ($arr as $v) {
$len = wordLen($v);
if ($len > 4)
$str2[] = $v;
}
$str3 = implode(" ", $str2);
echo $str3;//输出:今天天气好啊 没干什么啊
function wordLen($str) {
preg_match_all("/[\xa0-\xff]?./", $str, $arr);
return count($arr[0]);
}
?>