如何去掉简单的句子,去掉到第三个句号


How to strip simple sentence, strip up to third full stop?

我有一个很长的文本字符串,我如何将输出限制为计数句号,并只输出到第三个句号?

Ex Raw:

Lorem Ipsum只是印刷和排版行业的伪文本。自15世纪以来,Lorem Ipsum一直是该行业的标准伪文本,当时一位不知名的印刷商拿走了一个打字盘,并将其搅乱以制作一本打字样本书。它不仅存活了五个世纪,而且在电子排版的飞跃中保持了基本不变。它不仅存活了五个世纪,而且在电子排版的飞跃中保持了基本不变。

所需输出

Lorem Ipsum只是印刷和排版行业的伪文本。自15世纪以来,Lorem Ipsum一直是该行业的标准伪文本,当时一位不知名的印刷商拿走了一个打字盘,并将其搅乱以制作一本打字样本书。

 // Long text
 $profile_desc = 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.';
 // Split long text on each full stop.
 $profile_desc_out = explode( '. ', $profile_desc );
 $i = 0;
 // Repeat 3 times to get three sentences 
 foreach( $profile_desc_out as $profile_desc_output ){
   echo $profile_desc_output;
   if( ++$i > 3 ) {
     break;
   }
 }
 // How to incorporate implode() function to put back together? 

一如既往,RegExp前来救援:)

3是要显示的最大语句数。1是最小计数。

// Long text
$profile_desc = "This paragraph. Has. More. Than three. Sentences.";
preg_match('#^(?:[^'.]+'.){1,3}#', $profile_desc, $matches);
echo $matches[0], PHP_EOL;

输出:

This paragraph. Has. More.