PHP - get first two sentences of a text?

后端 未结 9 1901
慢半拍i
慢半拍i 2021-02-05 22:52

My variable $content contains my text. I want to create an excerpt from $content and display the first sentence and if the sentence is shorter than 15

9条回答
  •  终归单人心
    2021-02-05 23:20

    I know this is an old post but I was looking for the same thing.

    preg_match('/^([^.!?]*[\.!?]+){0,2}/', strip_tags($text), $abstract);
    echo $abstract[0];
    

提交回复
热议问题