What are best practices for finding and manipulating line endings in PHP text processing?

When working with text in PHP, it's important to be able to handle different line endings (such as \n, \r, or \r\n) that may be present in the input. One common approach is to normalize line endings to a consistent format (e.g., \n) before processing the text further. This can be done using PHP's built-in functions like `str_replace` or `preg_replace`.

// Sample text with mixed line endings
$text = "Hello\r\nworld\n!";

// Normalize line endings to \n
$text = str_replace(["\r\n", "\r"], "\n", $text);

// Now $text contains "Hello\nworld\n!"
echo $text;