Are there best practices for handling whitespace removal in PHP regex operations?

When using regex operations in PHP to remove whitespace, it is important to use the correct regex pattern to ensure that all types of whitespace characters are removed. One common approach is to use the \s pattern, which matches any whitespace character including spaces, tabs, and line breaks. Additionally, using the preg_replace function with the correct pattern can efficiently remove whitespace from a string.

// Example code snippet to remove whitespace using regex in PHP
$string = "  Hello   World  ";
$clean_string = preg_replace('/\s+/', '', $string);
echo $clean_string; // Output: HelloWorld