Check if URL has certain string with PHP

Try something like this. The first row builds your URL and the rest check if it contains the word “car”.

$url="http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];


if (strpos($url,'car') !== false) {
    echo 'Car exists.';
} else {
    echo 'No cars.';
}

Leave a Comment