I recently had to import some HTTP URLs that needed converting to HTTPS; Here’s how I did it. This is better than just running a str_replace
because it only replaces http://
if it appears at the beginning of the string.
$string = 'http://www.texelate.co.uk';
$prefix = 'http://';
// Jupix sends links as http:// so change to https://
if (substr($string, 0, mb_strlen($prefix)) === $prefix) {
$string = 'https://' . mb_substr($string, mb_strlen($prefix));
}
echo $string; // https://www.texelate.co.uk
Tim Bennett is a freelance web designer from Leeds. He has a First Class Honours degree in Computing from
Leeds Metropolitan University and currently runs his own one-man web design company, Texelate.