src/Utilities/Uri.php
public static function addProtocolToUrl($url, $protocol = 'http')
    {
        $pattern = sprintf('/^%s.*/', $protocol);

        if ((bool)preg_match($pattern, $url)) {
            return $url;
        }

        return sprintf('%s://%s', $protocol, $url);
    }
public static function addProtocolToUrl($url, $protocol = 'http')
    {
        $pattern = sprintf('/^%s.*/', $protocol);

        if ((bool)preg_match($pattern, $url)) {
            return $url;
        }

        return sprintf('%s://%s', $protocol, $url);
    }
public static function addProtocolToUrl ( $ url , $ protocol = 'http' ) { $ pattern = sprintf ( '/^%s.*/' , $ protocol ) ; if ( ( bool ) preg_match ( $ pattern , $ url ) ) { return $ url ; } return sprintf ( '%s://%s' , $ protocol , $ url ) ; }
Adds protocol to given url, if the url does not contain given protocol.
Returns the new url.

@param string $url      Url string
@param string $protocol (optional) Protocol string
@return string
Adds protocol to given url if the url does not contain given protocol . Returns the new url .