这个问题与我发布的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;
}
如您所见,有许多图像目录。我想添加../
所以所有images目录都是这样的:
background-image:url(../images/sheet.gif);
以及所有其他图像目录。
如何创建一个自动读取style.css的PHP代码,然后插入:../
?
来自previous post的答案,
$css = str_replace("url(images/", "url(../images/", $css);
我在这里仍然缺少什么?
这是我的学校项目。请帮忙。谢谢!
答案 0 :(得分:1)
$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