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

如何验证网址是否正确

WBOY
Release: 2016-06-13 13:51:19
Original
1764 people have browsed it

怎么验证网址是否正确?
网址格式有:
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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template