What are some common pitfalls when dealing with line breaks and whitespace in PHP string manipulation?
One common pitfall when dealing with line breaks and whitespace in PHP string manipulation is not properly handling different types of line breaks (e.g., \n, \r, \r\n). To ensure consistent behavior, you can use the PHP function `preg_replace` with a regular expression pattern that matches all types of line breaks and whitespace characters.
// Example: Replace all line breaks and whitespace characters with a single space
$string = "Hello\nWorld\r\n PHP";
$cleaned_string = preg_replace('/\s+/', ' ', $string);
echo $cleaned_string;