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 to compare strings in PHP?How do I find the length of a string in PHP?
How do I remove trailing whitespace from a string?
What is the usage of {} in strings?
How do I make sure a string is a certain length?
