03-Apr-2023
.
Admin
Hi Dev,
In this quick example, let's see php count lines from string example. this example will help you how to find strign count lines in php?. I’m going to show you about count Lines of string in php example. This post will give you simple example of how to use function to count lines of string in php?. follow bellow step for how to find string count lines in php?.
In this example to php Count lines of string in PHP. in this example, we will use to substr_count() function used to find string lines. so Let's see the following example with output.
Example: Count Lines from string
index.php
<?php
$str = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
//Count String Lines
$result = substr_count( $str, "\n" );
echo $result;
?>
Output:
5
I hope it could help you...
#PHP