这个问题与我发布的一个问题有关 earlier: ,我这里有包含这段代码的 css 文件:
body {
background-image:url(images/background.gif);
color: #7a7e33;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
margin: 0px;
padding: 0px;
}
#header {
background-image:url(images/header.jpg);
width: 707px;
height:300px;
display:block;
margin-left: 240px;
padding:0px;
}
#content{
background-image:url(images/sheetmiddle.gif);
background-repeat:repeat-y;
position:relative;
}
#sheettop{
background-image:url(images/sheet.gif);
background-repeat:no-repeat;
width:707px;
}
#footer{
background-image:url(images/footer.gif);
width:707px;
height:86px;
margin-left:242px;
}
如您所见,有很多图像目录。我想添加 ../
所以所有的图像目录将如下所示:
background-image:url(../images/sheet.gif);
以及所有其他图像目录。
我怎样才能制作一个自动读取 style.css 然后插入这个的 php 代码:../
?
来 self 的 previous post 上的回答,
$css = str_replace("url(images/", "url(../images/", $css);
我还缺少什么?
这是我的学校元素。请帮忙。谢谢!
最佳答案
$css = file_get_contents('/path/to/your/css/file'); // slurp in the file
$css = str_replace(...); // modify the data
file_put_contents('/path/to/your/css/file', $css); // spit it back out
关于php - 更改CSS文件中所有图像的目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4887109/