What best practices should be followed when using preg_quote in PHP to escape special characters in patterns?

When using preg_quote in PHP to escape special characters in patterns, it is important to always provide the second parameter which specifies the delimiter character used in the pattern. This ensures that the function escapes the delimiter as well, preventing potential issues with pattern matching. Additionally, it is recommended to use single quotes for the pattern string to avoid conflicts with PHP string interpolation.

$pattern = 'example.com';
$escaped_pattern = preg_quote($pattern, '/');
echo $escaped_pattern; // Output: example\.com