PHP - get first two sentences of a text?

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

    This would make sure it never returned a half-word;

    $short = substr($content, 0, 100);
    $short = explode(' ', $short);
    array_pop($short);
    $short = implode(' ', $short);
    print $short;
    

提交回复
热议问题