0

This question is related to one i posted earlier:, I have here the css file containing this code:

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;
}

As you can see, there are many images directories. I want to add ../ so all the images directory will look like this:

background-image:url(../images/sheet.gif);

And all the other image directory. How can I make a php code that will automatically read the style.css then insert this: ../ ?

From the answer on my previous post,

$css = str_replace("url(images/", "url(../images/", $css);

What am i still missing here?

This is for my school project. Please help. Thanks!

7
  • 3
    why not just open up the style.css and do a search and replace?
    – KJYe.Name
    Feb 3, 2011 at 14:08
  • Do you need to know how to open up the CSS file and read it?
    – Malachi
    Feb 3, 2011 at 14:09
  • what do you get from $css - what doesn't work. The str_replace looks fine.
    – ocodo
    Feb 3, 2011 at 14:10
  • If this is what passes for a parser project these days, sigh.
    – ocodo
    Feb 3, 2011 at 14:12
  • I assume this is part of a larger problem i.e. changing images based on theme, just ask us for that because maybe this is not the best solution for it.
    – Arvin
    Feb 3, 2011 at 14:24

1 Answer 1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.