How do we count paragraphs or newlines?
For instance if you want to count line breaks - occurrances of the \n character, then this can be done very simply with this function.
Here is an example of how to use substr_count to count newlines:
<?php
$sentence = "This is a sentence that has lots
of
line breaks
in it
for no apparent
reason!!!";
$numberoflinebreaks = substr_count($sentence,"\n");
echo "There are $numberoflinebreaks line breaks in that sentence";
//There are ten line breaks in that sentence
?>
Comment on this Question and Answer >>>
ASK A QUESTION
More strings PHP Questions
How do I find the length of a string in PHP?How do I break email address into username and hostname?
How do I calculate the metaphone of a string?
how to compare strings in PHP?
How do I find the last occurrence of a character in a string?
