src/Control/Director.php
public static function makeRelative($url)
    {
        // Allow for the accidental inclusion whitespace and // in the URL
        $url = preg_replace('#([^:])//#', '\\1/', trim($url));

        // If using a real url, remove protocol / hostname / auth / port
        if (preg_match('#^(?<protocol>https?:)?//(?<hostpart>[^/]*)(?<url>(/.*)?)$#i', $url, $matches)) {
            $url = $matches['url'];
        }

        // Empty case
        if (trim($url, '\\/') === '') {
            return '';
        }

        // Remove base folder or url
        foreach ([self::publicFolder(), self::baseFolder(), self::baseURL()] as $base) {
            // Ensure single / doesn't break comparison (unless it would make base empty)
            $base = rtrim($base, '\\/') ?: $base;
            if (stripos($url, $base) === 0) {
                return ltrim(substr($url, strlen($base)), '\\/');
            }
        }

        // Nothing matched, fall back to returning the original URL
        return $url;
    }
public static function makeRelative($url)
    {
        // Allow for the accidental inclusion whitespace and // in the URL
        $url = preg_replace('#([^:])//#', '\\1/', trim($url));

        // If using a real url, remove protocol / hostname / auth / port
        if (preg_match('#^(?<protocol>https?:)?//(?<hostpart>[^/]*)(?<url>(/.*)?)$#i', $url, $matches)) {
            $url = $matches['url'];
        }

        // Empty case
        if (trim($url, '\\/') === '') {
            return '';
        }

        // Remove base folder or url
        foreach ([self::publicFolder(), self::baseFolder(), self::baseURL()] as $base) {
            // Ensure single / doesn't break comparison (unless it would make base empty)
            $base = rtrim($base, '\\/') ?: $base;
            if (stripos($url, $base) === 0) {
                return ltrim(substr($url, strlen($base)), '\\/');
            }
        }

        // Nothing matched, fall back to returning the original URL
        return $url;
    }
public static function makeRelative ( $ url ) { // Allow for the accidental inclusion whitespace and // in the URL $ url = preg_replace ( '#([^:])//#' , '\\1/' , trim ( $ url ) ) ; // If using a real url, remove protocol / hostname / auth / port if ( preg_match ( '#^(?<protocol>https?:)?//(?<hostpart>[^/]*)(?<url>(/.*)?)$#i' , $ url , $ matches ) ) { $ url = $ matches [ 'url' ] ; } // Empty case if ( trim ( $ url , '\\/' ) === '' ) { return '' ; } // Remove base folder or url foreach ( [ self :: publicFolder ( ) , self :: baseFolder ( ) , self :: baseURL ( ) ] as $ base ) { // Ensure single / doesn't break comparison (unless it would make base empty) $ base = rtrim ( $ base , '\\/' ) ? : $ base ; if ( stripos ( $ url , $ base ) === 0 ) { return ltrim ( substr ( $ url , strlen ( $ base ) ) , '\\/' ) ; } } // Nothing matched, fall back to returning the original URL return $ url ; }
Turns an absolute URL or folder into one that's relative to the root of the site. This is useful
when turning a URL into a filesystem reference, or vice versa.

Note: You should check {@link Director::is_site_url()} if making an untrusted url relative prior
to calling this function.

@param string $url Accepts both a URL or a filesystem path.
@return string
Turns an absolute URL or folder into one that s relative to the root of the site . This is useful when turning a URL into a filesystem reference or vice versa .