- array_push: documentation ( source)
- explode: documentation ( source)
- array_pop: documentation ( source)
- join: documentation ( source)
<?php
function absolute_path($base, $relative)
{
list($stack, $parts) = [explode('/', $base), explode('/', $relative)];
array_pop($stack);
for ($i = 0; $i < count($parts); $i++)
{
if ($parts[$i] == '')
continue;
elseif ($parts[$i] == '..')
array_pop($stack);
else
array_push($stack, $parts[$i]);
}
return join('/', $stack);
}
echo absolute_path(
'http://mhelper.ru/project/dev/works/ElenaBeauty/index.html',
'../../css/reset.css'
);