First, I need to check the URL string, if the protocol of URL is https
, then I need to replace http
in PHP.
So the inputs and outputs of this php function must be like this:
Input -> https://example.com/example/https.php
Output-> http://example.com/example/https.php
Input -> http://example.com/example/https.php
Output-> http://example.com/example/https.php
This will ensure it's at the beginning of the string and it's followed by ://
$input = 'https://example.com/example/https.php';
echo preg_replace('/^https(?=:\/\/)/i','http',$input);
function remove_ssl ($url) {
if (strpos($url, 'https://') == 0) {
$url = 'http://' . substr($url, 7);
}
return $url;
}
The
strpos($url, 'https://') == 0
Is on purpose and is not === because we only want the case when the URL starts with https:// and just replace that one.
See also: http://php.net/manual/en/function.parse-url.php
...
$parsed_url = parse_url($url);
if ($parsed_url['scheme'] == 'https') {
$url = 'http://' . substr($url, 7);
}
return $url;
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With