Last active
September 18, 2021 21:36
-
-
Save ano/b4077a1ad0362b01374df4f78c5ca9f9 to your computer and use it in GitHub Desktop.
Get the first sentence from a string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Source: https://electrictoolbox.com/get-first-sentence-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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment