Every line is terminated by a 'newline' character, so counting newlines using substr_count() does that.
Just remember to add a check to see wether the string really ends on a newline, otherwise the last 'line' would not end with a newline, and you'd count one line too few.