可能重复:
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';
答案 0 :(得分:5)
使用PHP提供的filter_var
函数(另请参阅types of filters):
$is_url = filter_var($url, FILTER_VALIDATE_URL);