Back to HTMLHelper class

Method convertToRelativePath

protected static string
convertToRelativePath
(mixed $path)
Method that takes a file path and converts it to a relative path
Parameters
  • string $path The actual path of the file
Returns
  • string The relative path of the file
Since
  • 4.0.0
Class: HTMLHelper
Project: Joomla

Method convertToRelativePath - Source code

/**
 * Method that takes a file path and converts it to a relative path
 *
 * @param   string  $path  The actual path of the file
 *
 * @return  string  The relative path of the file
 *
 * @since   4.0.0
 */
protected static function convertToRelativePath($path)
{
    $relativeFilePath = Uri::root(true) . str_replace(JPATH_ROOT, '', $path);
    // On windows devices we need to replace "\" with "/" otherwise some browsers will not load the asset
    return str_replace(DIRECTORY_SEPARATOR, '/', $relativeFilePath);
}