【发布时间】:2016-06-18 19:40:09
【问题描述】:
我正在将多个 CSS 文件合并为一个(CSS 文件的层次结构是不同的),所以我需要将 CSS 文件中的相对 URL 转换为绝对 URL。
以下是要求;
CSS file URL: http://example.com/template/default/css/style.css
Domain: http://example.com
输入
#test {
background:url(../images/test.jpg);
background:url( 'test.jpg' );
background:url("../../common/test.jpg" );
background:url(http://example.com/test.jpg);
background:url('https://example.com/test.jpg');
background:url( '//example.com/test.jpg' );
background:url( "//example.com/test.jpg" );
background:url(//example.com/test.jpg);
}
需要的输出
#test {
background:url(http://example.com/template/default/images/test.jpg);
background:url( 'http://example.com/template/default/css/test.jpg' );
background:url("http://example.com/template/common/test.jpg" );
background:url(http://example.com/test.jpg);
background:url('https://example.com/test.jpg');
background:url( '//example.com/test.jpg' );
background:url( "//example.com/test.jpg" );
background:url(//example.com/test.jpg);
}
请注意../ 和../../ 的相对路径。
我已经尝试了来自 preg_replace() regex to match relative url() paths in CSS files 的类似解决方案,但这是不同的,我无法让它适用于我的情况。
提前感谢您的帮助。
【问题讨论】:
-
如果答案正确,请标记答案或更新答案...