网址 url 正则表达式实例
<?php function funcUrl($str) //url正则表达试 { return (preg_match("/[a-zA-z]+:\/\/[^\s]+/", $str)) ? true : false; } if ($_POST) { if (funcUrl($_POST['url'])) { echo $_POST['url']; } else { exit('不是有效url'); } } ?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>网址 url 正则表达式实例</title> </head> <body> <form id="phprm" name="phprm" method="post" action=""> <input name="url" type="text" /> <input name="" type="submit" value="提交 "/> </form> 输入http://www.phprm.com教程 输出http://www.phprm.com 输入 qqq 输出 不是有效url </body> </html>
本文地址:http://www.phprm.com/code/6dd10499c725a9a5f123cdade6f7e1be.html
转载随意,但请附上文章地址:-)