Learning never exhausts the mind

By

This quick PHP snippet will return the first sentence of a specified string. Very useful for generating post or page abstracts, extracts or descriptions.
function firstPunctuation($string)
{
  $excl = strpos($string,"!");
  $stop = strpos($string,".");
  
  if ($excl === false) $excl = 9999;
  if ($stop === false) $stop = 9999;
  
  if ($excl < $stop) return $excl + 1;
  if ($excl > $stop) return $stop + 1;

}

 

Sharing is caring!

If you enjoyed this post, please share it with others. Click one of the social media buttons below to share on Facebook, Twitter, LinkedIn, Pinterest or email to a friend.

Leave a Reply

Fields marked with * are mandatory.

We respect your privacy, and will not make your email public. Hashed email address may be checked against Gravatar service to retrieve avatars. This site uses Akismet to reduce spam. Learn how your comment data is processed.