使用PHP检查URL是否具有某些字符串 [英] Check if URL has certain string with PHP

查看:103
本文介绍了使用PHP检查URL是否具有某些字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道URL中是否存在某些单词.

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

例如,如果URL中包含单词car,例如www.domain.com/car/或www.domain.com/car/audi/,它将回显"car is exist",如果没有,则回显没有车.

For example, if word car is in the URL, like www.domain.com/car/ or www.domain.com/car/audi/ it would echo 'car is exist' and if there's nothing it would echo 'no cars'.

推荐答案

尝试类似的方法.第一行建立您的URL,其余行检查其是否包含单词"car".

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.';
}

这篇关于使用PHP检查URL是否具有某些字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆