What are some best practices for handling special characters or modifiers within preg_match in PHP?

Special characters or modifiers within preg_match in PHP can sometimes cause unexpected behavior or errors. To handle this, it's best practice to use the preg_quote() function to escape any special characters before using them in the regular expression pattern.

// Example of using preg_quote() to escape special characters in a string before using it in preg_match
$pattern = '/^' . preg_quote($input_string, '/') . '$/';
if (preg_match($pattern, $subject)) {
    echo "Match found!";
} else {
    echo "No match found.";
}