php一句代码判断网址是否包含http或https

//方法一
$preg = "/http[s]?:\/\/[\w.]+[\w\/]*[\w.]*\??[\w=&\+\%]*/is";
if (!preg_match($preg, $str)) {
    $this->json(null, '该网址不合法,请输入正确的url', 1001);
}
//方法二
$str = "https://xx.xx.xx";
if(preg_match("/^(http:\/\/|https:\/\/).*$/",$str)){
echo "yes";
}
最后修改于:2021-09-29 22:45
文章链接: https://oct.cn/view/3
版权声明: 本站所有文章除特别声明外。转载请注明来自 十月笔记