isurl
- <?php$url = "http://www.example.com";if(!filter_var($url, FILTER_VALIDATE_URL)) { echo "URL is not valid"; }else { echo "URL is valid"; }?>
- <?phpfunction isUrl($s) { return preg_match('/^http[s]?:\/\/'. '(([0-9]{1,3}\.){3}[0-9]{1,3}'. // IP形式的URL- 199.194.52.184 '|'. // 允许IP和DOMAIN(域名) '([0-9a-z_!~*\'()-]+\.)*'. // 三级域验证- www. '([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\.'. // 二级域验证 '[a-z]{2,6})'. // 顶级域验证.com or .museum '(:[0-9]{1,4})?'. // 端口- :80 '((\/\?)|'. // 如果含有文件对文件部分进行校验 '(\/[0-9a-zA-Z_!~\*\'\(\)\.;\?:@&=\+\$,%#-\/]*)?)$/', $s) == 1; }$url = "https://www.baidu.com";if(isUrl($url)){ echo 11;}else{ echo 00;}?>