I want to convert ../
into full paths.For example I have following urls in css in https://example.com/folder1/folder2/style.css
img/example1.png
/img/example2.png
../img/example3.png
../../img/example4.png
https://example.com/folder1/folder2/example5.png
I want to convert them into full path like below for above examples
https://example.com/folder1/folder2/img/example1.png
https://example.com/folder1/folder2/img/example1.png
https://example.com/folder1/img/example1.png
https://example.com/img/example1.png
https://example.com/folder1/folder2/example5.png
I tried something like below
$domain = "https://example.com";
function convertPath($str)
{
global $domain;
if(substr( $str, 0, 4 ) == "http")
{
return $str;
}
if(substr( $str, 0, 1 ) == "/")
{
return $domain.$str;
}
}
I know am complicating it , There must be some easy way to this kind of operation.Please guide me .Thank you.