search

Home  >  Q&A  >  body text

php 怎么验证输入的url合法性?

小白小白2884 days ago998

reply all(2)I'll reply

  • 数据分析师

    数据分析师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.

    reply
    0
  • 迷茫

    迷茫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地址非法';
    }
    ?>


    reply
    1
  • Cancelreply