Counting the number lines in a string – 2 Solution
Counting the number lines in a string with explode function:
<?php
$lines = explode("\n", $string);
$nr_lines = count($lines)-1;
?>
Counting the number lines in a string with substr_count function:
<?php
$nr_lines = substr_count($string,"\n");
?>
the 2′nd solution is better.
Categories: Bookmarks, PhP, Tech count line, explode, explode string, lines in a string, number lines, php string, str count, substr count, substr_count








