数据分析师2017-09-30 23:36:30
php How to verify the legality of the entered url?-PHP Chinese website Q&A-php How to verify the legality of the entered url?-PHP Chinese website Q&A
Take a look and learn.
迷茫2016-12-22 15:15:12
首先,定义函数check_url:
<?php function check_url($url){ if(!preg_match('/http:\/\/[\w.]+[\w\/]*[\w.]*\??[\w=&\+\%]*/is',$url)){ return false; } return true; } ?>
使用方法:
<?php $url='需验证的url'; $isurl=check_url($url); if($isurl){ echo 'url地址合法'; }else{ echo 'url地址非法'; } ?>