验证变量的内容是否为域

时间:2011-12-20 06:31:18

标签: php string validation

  

可能重复:
  How to validate domain name in PHP?
  Better way to validate a URL in PHP

如果$variable是网站地址,我该如何检查?

就像这样,它应该给true

$varialbe = 'http://google.com';

对于此false

$variable = 'this value can be anything, but we know its not a domain';

1 个答案:

答案 0 :(得分:5)

使用PHP提供的filter_var函数(另请参阅types of filters):

$is_url = filter_var($url, FILTER_VALIDATE_URL);