PHP - get first two sentences of a text?

后端 未结 9 1904
慢半拍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:34

    If I were you, I'd choose to pick only the first sentence.

    $t='Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Vestibulum justo eu leo.'; //input text
    $fp=explode('. ',$t); //first phrase
    echo $fp[0].'.'; //note I added the final ponctuation
    

    This would simplyfy things a lot.

提交回复
热议问题