0

我想出了这段代码,它从文本中提取第一句话。但是我需要提取前 2 个句子,但我不知道该怎么做。有任何想法吗?

$input = get_field('fl_description');

$pos = strpos($input, '.' , 1);
$output = substr($input, 0, $pos+1);

echo $output;
4

2 回答 2

0

尝试使用带有分隔符“.”的爆炸方法。将限制设置为 2,将创建包含 2 个元素的数组,其中前 2 个句子。

$arrayOfSentences = explode ('.' , $input ,2 );

回声 $arrayOfSentences[0]+" "+$arrayOfSentences[1];

更多关于爆炸方法: http: //php.net/manual/pl/function.explode.php

于 2013-04-10T18:42:14.410 回答
0
$input = get_field('fl_description');
$pos = strpos($input, '.' , 1); 
$pos = strpos($input, '.' , $pos+1); 
$output = substr($input, 0, $pos+1);
echo $output; '
于 2013-04-10T18:42:25.307 回答