How can PHP developers address the challenge of accurately counting line breaks in a text input without affecting the overall string length calculation?

When counting line breaks in a text input, PHP developers can use the `mb_substr_count()` function to accurately count line breaks without affecting the overall string length calculation. This function counts the number of occurrences of a substring within a string, allowing developers to specifically target line breaks ("\n" or "\r\n") while excluding them from the overall string length calculation.

$text = "This is a sample text with\nmultiple line breaks\n";
$lineBreaks = mb_substr_count($text, "\n") + mb_substr_count($text, "\r\n");

echo "Number of line breaks: " . $lineBreaks . "\n";
echo "String length: " . mb_strlen($text) . "\n";