Are there any best practices for escaping whitespace characters in PHP when performing string searches?

When performing string searches in PHP, it is important to properly escape whitespace characters to ensure accurate results. One common approach is to use the preg_quote() function to escape any whitespace characters before using them in a regular expression pattern for the search.

$searchTerm = "white space";
$escapedSearchTerm = preg_quote($searchTerm, '/');
$pattern = "/$escapedSearchTerm/";

$stringToSearch = "This is a string with white space characters";
if (preg_match($pattern, $stringToSearch)) {
    echo "Search term found!";
} else {
    echo "Search term not found.";
}