Heim  >  Artikel  >  Backend-Entwicklung  >  如何验证网址是否正确

如何验证网址是否正确

WBOY
WBOYOriginal
2016-06-13 09:59:262166Durchsuche

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

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn