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 add commas easily to a string of numbers?How do I find the last occurrence of a character in a string?
How do you check if a variable is set or not in PHP?
How do I remove space from the start of a PHP string?
How do I one-way encrypt a string in PHP?
