Check if URL has certain string with PHP

后端 未结 12 722
自闭症患者
自闭症患者 2020-11-30 17:19

I would like to know if some word is present in the URL.

For example, if word car is in the URL, like www.domain.com/car/ or www.domain.com/car/audi/ it would echo \

12条回答
  •  伪装坚强ぢ
    2020-11-30 17:48

    Surely this is the correct way round....

    $url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
    
    
    if (!strpos($url,'mysql')) {
    echo 'No mysql.'; //swapped with other echo statement
    } else {
    echo 'Mysql exists.';
    }
    

    Otherwise its reporting the opposite way it should...

提交回复
热议问题