检查网址是否包含http://或https://

use*_*341 5 php http

可能重复:
检查URL是否包含http或https

什么是用于确定给定URL是否包含http://https://在开头使用PHP和正则表达式的代码?

Mih*_*rga 26

你可以使用parse_url

<?php
$url = parse_url('https://example.org');

if($url['scheme'] == 'https'){
   // is https;
}
?>
Run Code Online (Sandbox Code Playgroud)


tas*_*ski 10

if (substr($string, 0, 7) == "http://")
    $res = "http";

if (substr($string, 0, 8) == "https://")
    $res = "https";
Run Code Online (Sandbox Code Playgroud)