Home > Bookmarks, PhP, Tech > Counting the number lines in a string – 2 Solution

Counting the number lines in a string – 2 Solution

February 20th, 2009 Leave a comment Go to comments

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.

  1. No comments yet.
  1. No trackbacks yet.
GoCache - ByREV-Cache v1.0 - live served in : 0.206432 sec (gzip)