I am in the process of trying to figure out how to mask a path over relative paths. This is a custom minifier script I'm implementing for CSS files, and need to absolute the relative paths.
So say I have the following in a CSS file url('../images/file.jpg')
This file is sitting in the directory /application/module/assets/css/theme.css
, this would mean the new path in the CSS file would need to be /application/module/assets/images/file.jpg
.
Now say there is a CSS file in /application/plugins/pluginName/assets/css/plugin.css
and links to ../../../../module/assets/images/image.jpg
, the replaced path would need to be /application/module/assets/images/file.jpg
So I'm asking, is there a nice preg_replace setup I can use to do this:
str_replace('../', '/path/to/file/', $file);
str_replace('../../', '/path/to/', $file);
str_replace('../../../', '/path/', $file);
Hopefully this makes sense...
Regards,
Andrew