文章分词有两种情况:
1. < p > the first paragraph < / p > < p > the second paragraph < / p >...
2. < p > the first period of < br / > < br / > the second paragraph < br / > < br / > the third paragraph < / p >
我编写代码如下:
$body_arr = preg_split('/\<\/?p\>/',$body,-1,PREG_SPLIT_NO_EMPTY);
echo count($body_arr);
if(count($body_arr)<4)
{
$body_arr = preg_split('/(\<br\/?\>)\s*\\1/',$body,-1,PREG_SPLIT_NO_EMPTY);
$body1 = $body2 = $body3 = '';
$total = count($body_arr);
$maxed = max(floor($total / 2), 3);
foreach ($body_arr as $k => $v)
{
if ($k == 0)
{
$body1 = $v . "<br><br>";
}
else if ($k < $maxed)
{
$body2.=$v . "<br><br>";
}
else
{
$body3.=$v . "<br><br>" ;
}
}
}
这是第二个
结果是错误的。