How can one check the requested URL in PHP to determine if it contains a specific article ID?

To check if a requested URL in PHP contains a specific article ID, you can use regular expressions to extract the article ID from the URL and then compare it with the specific ID you are looking for. You can use the preg_match function to match the article ID pattern in the URL and then check if it matches the specific ID.

$url = $_SERVER['REQUEST_URI'];
$article_id = 123; // Specific article ID you are looking for

if (preg_match('/\/article\/(\d+)/', $url, $matches)) {
    $url_article_id = $matches[1];
    
    if ($url_article_id == $article_id) {
        echo "URL contains the specific article ID: $article_id";
    } else {
        echo "URL does not contain the specific article ID: $article_id";
    }
} else {
    echo "URL does not match the expected pattern for article ID";
}