Check whether url contains http:// or https:// [du

2019-05-01 17:35发布

Possible Duplicate:
Check if the url is contains the http or https

What is the code to figure out whether the given URL contains http:// or https:// at the beginning using PHP and regular expressions?

标签: php http
3条回答
做个烂人
2楼-- · 2019-05-01 18:01

you can use parse_url

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

if($url['scheme'] == 'https'){
   // is https;
}
?>
查看更多
姐就是有狂的资本
3楼-- · 2019-05-01 18:07
if (substr($string, 0, 7) == "http://")
    $res = "http";

if (substr($string, 0, 8) == "https://")
    $res = "https";
查看更多
霸刀☆藐视天下
4楼-- · 2019-05-01 18:08

Maybe this could help

$_SERVER['SERVER_PROTOCOL'];
查看更多
登录 后发表回答