Display first sentence with PHP

To display the first sentence of the paragraph with PHP. Use this code

Code
[php]
function first_sentence($content) {
$pos = strpos($content, ‘.’);
if($pos === false) {
return $content;
}
else {
return substr($content, 0, $pos+1);
}
}
[/php]

Invoke the function like

[php]
echo first_sentence($content);
[/php]

Permanent link to this article: https://blog.openshell.in/2011/07/display-first-sentence-with-php/

Leave a Reply

Your email address will not be published.