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.
Be First to Comment