PHP - Get first words of content function

0 votes
94 views
added Aug 8, 2019 in PHP by lcjr First Warrant Officer (9,190 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.
...