Home  >  Article  >  Backend Development  >  如何验证网址是否正确

如何验证网址是否正确

WBOY
WBOYOriginal
2016-06-13 09:59:262163browse

怎么验证网址是否正确?
网址格式有:
http://www.abc.com
http://abc.com
http://www.abc.com/
http://abc.com
http://www.abc.com/s/

http://www.abc.com/s/s/

http://www.abc.com/s/xx.htm

http://www.abc.com/s/xx.php

http://www.abc.com/s/xx.asp/

https://www.abc.com/s/xx

ftp://www.abc.com/

等等

if (preg_match("/?????????????????//",$url)){//这里怎么写?能够应对各种可能的网址格式?
echo "网址正确";
}else{
echo "网址错误";
}




------解决方案--------------------
"/(http:\/\/)?w{3}\.[^/.]+\.(com|net|cn|org).(cn)?/i"
------解决方案--------------------
/^[a-zA-Z]+:\/\/.+/i

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn