What are some potential pitfalls to be aware of when using search patterns for URLs in PHP?

Potential pitfalls when using search patterns for URLs in PHP include not properly sanitizing user input, which can lead to security vulnerabilities such as SQL injection or cross-site scripting attacks. It is important to validate and sanitize any user input before using it in a search pattern to prevent these types of attacks.

// Example of sanitizing user input before using it in a search pattern
$url = $_GET['url'] ?? ''; // Get the URL from user input
$sanitized_url = filter_var($url, FILTER_SANITIZE_URL); // Sanitize the URL
if ($sanitized_url) {
    // Use the sanitized URL in the search pattern
    $pattern = '/^' . preg_quote($sanitized_url, '/') . '$/';
    // Rest of the code here
} else {
    // Handle invalid URL input
    echo 'Invalid URL input';
}