PHP检查域是否等于值,然后执行操作 [英] php check if domain equals value, then perform action
本文介绍了PHP检查域是否等于值,然后执行操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要获取一个包含URL的变量,并检查该域是否等于某个域,如果存在,则回显一个变量,否则,回显另一个变量.
I need to take a variable that contains a URL, and check to see if the domain equals a certain domain, if it does, echo one variable, if not, echo another.
$domain = "http://www.google.com/docs";
if ($domain == google.com)
{ echo "yes"; }
else
{ echo "no"; }
我不确定如何在第二行中检查域以查看$ domain是否在if语句中包含网址.
Im not sure how to write the second line where it checks the domain to see if $domain contains the url in the if statement.
推荐答案
这是通过使用 parse_url
:
This is done by using parse_url
:
$host = parse_url($domain, PHP_URL_HOST);
if($host == 'www.google.com') {
// do something
}
这篇关于PHP检查域是否等于值,然后执行操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文