Home  >  Article  >  Backend Development  >  Javascript与PHP验证用户输入URL地址是否正确_PHP

Javascript与PHP验证用户输入URL地址是否正确_PHP

WBOY
WBOYOriginal
2016-05-31 19:29:20809browse

本文实例讲述了Javascript与PHP验证用户输入URL地址是否正确的方法,分享给大家供大家参考。具体方法如下:

1.javascript检测URL地址有效性:

代码如下:


 URL:
 
 


 
 

2.PHP检测URL地址有效性

代码如下:

function is_url($str){
return preg_match("/^http://[A-Za-z0-9]+.[A-Za-z0-9]+[/=?%-&_~`@[]':+!]*([^"])*$/", $str);
}
?>

如果要尝试是否可以正常方法我们可使用file_get_contents()函数来验证就可以了。

希望本文所述对大家的PHP程序设计有所帮助。

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