Are you looking for more than 1 \n
in general? if so:
if (preg_match_all('#\\n#', $string, $matches) > 1) {
//More than 1 \n
}
Or without regex:
if (substr_count($string, "\n") > 1) {
//More than 1 \n
}
Or even (but it's far less efficient):
$chars = count_chars($string);
if (isset($chars[ord("\n")]) && $chars[ord("\n")] > 1) {
//More than 1 \n
}
If in a row:
if (preg_match_all('#\\n\\n+#', $string, $matches) > 0) {
//More than 1 \\n in a row
}
Edit: So, based on your edit, I can summize two possibilities about what you want to know.
If you want to know the number of \n
characters in a row (more than 1), you could do:
if (preg_match('#\\n\\n+#', $string, $match)) {
echo strlen($match[0]) . ' Consecutive \\n Characters Found!';
}
Or, if you wanted to know for each occurance:
if (preg_match_all('#\\n\\n+#', $string, $matches)) {
echo count($matches) . ' Total \\n\\n+ Matches Found';
foreach ($matches[0] as $key => $match) {
echo 'Match ' . $key . ' Has ' .
strlen($match) . ' Consecutive \\n Characters Found!';
}
}