What is the best practice for using regular expressions to manipulate text in PHP, specifically in the context of newline characters?

When working with regular expressions to manipulate text in PHP, it is important to consider newline characters (\n). To match newline characters in PHP, you can use the special metacharacter \r\n. If you want to replace newline characters with a different string, you can use the preg_replace() function with the appropriate regular expression pattern.

// Example code to replace newline characters with a space
$text = "Hello\nWorld!";
$new_text = preg_replace("/\r\n|\n|\r/", " ", $text);
echo $new_text; // Output: Hello World!