PHP - Get first words of content function

0 votes
175 views
added Aug 8, 2019 in PHP by lcjr First Warrant Officer (11,530 points)
<?php
function first_sentence($content) {
  $content = html_entity_decode(strip_tags($content));
  $pos = strpos($content, '.');             
  if($pos === false) {
      return $content;
  }
  else {
      return substr($content, 0, $pos+1);
  }
}
?>

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...