2013-04-10 27 views
0

我想出了從代碼中提取第一句話的代碼。但是,我需要提取前兩句話,我不知道該怎麼做。有任何想法嗎?使用PHP提取前2個句子

$input = get_field('fl_description'); 

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

echo $output; 

回答

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

這個工程..是它便宜? – 2013-04-10 18:52:39

0

嘗試使用具有分隔符「。」的爆炸方法。將限制設置爲2,將創建包含2個元素的數組,並帶有前2個句子。

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

echo $ arrayOfSentences [0] +「」+ $ arrayOfSentences [1];

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