PHP - replace http with https in URL PHP - replace http with https in URL php php

PHP - replace http with https in URL


$url = preg_replace("/^http:/i", "https:", $url);


$url = str_replace( 'http://', 'https://', $url );


One way:

$url = '%s//google.com';$protocol = 'http:';if(!isset($_POST['https'])) {     $protocol = 'https:';}$url = sprintf($url, $protocol);