php页面中,
$text="工作 人员 根据 每组 所用 时间 依次 排名 用时 最短的 队伍 成为 今天 比赛的 第一名 并 获得 11分 的 积分";
其中空格隔开的都是些词,我怎么输出 时间 这个词 的前二个词 到 时间 后三个词,也就是输出 每组 所用 时间 依次 排名 用时;
thanks
$text="工作 人员 根据 每组 所用 时间 依次 排名 用时 最短的 队伍 成为 今天 比赛的 第一名 并 获得 11分 的 积分";
其中空格隔开的都是些词,我怎么输出 时间 这个词 的前二个词 到 时间 后三个词,也就是输出 每组 所用 时间 依次 排名 用时;
thanks
$text_arr = explode(" ",$text);
$index = array_search("时间",$text_arr);
if($index === false){
echo "NG";
}else{
for($n=$index-2;$n<$index+3;$n++)
$result .= $text_arr[$n];
echo "Result=".$result;
}
preg_match('/(?:[^\s]+ ){2}时间(?: [^\s]+){3}/', $text, $reg);
print_r($reg);Array ( [0] => 每组 所用 时间 依次 排名 用时 )
string[] count = trim.split('|')
count[4]=="每组"
count[5]=="所用"
count[6]=="时间"count[7]=="依次"
count[8]=="排名"
count[9]=="用时"
$text_arr = explode(" ",$text);
$index = array_search("时间",$text_arr);
if($index === false){
echo "NG";
}else{
for($n=$index-2;$n<$index+3;$n++)
$result .= $text_arr[$n];
echo "Result=".$result;
}
可以了