1

Here's my css link for images:

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

I just want to add some: ../ to change the directory. So my code will look like this:

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

How will I do that? I don't need a whole CSS parser just the code to add the ../ for the images...

4
  • Not sure what is being asked here. Do you want to do this programmatically? Why? Commented Feb 3, 2011 at 12:22
  • CSS paths are relative to the CSS file. If you want to do that alter your directory structure surely? Commented Feb 3, 2011 at 12:25
  • @Beliskner yes. I have to change the css directory of codes Commented Feb 3, 2011 at 12:28
  • 2
    Your editor doesn't support Find & Replace? Why PHP? Commented Feb 3, 2011 at 12:30

5 Answers 5

4
$css = str_replace("url(images/", "url(../images/", $css);
Sign up to request clarification or add additional context in comments.

Comments

2

http://pear.php.net/package/HTML_CSS/

Comments

0

Could you not just do a find and replace in your CSS for "(images/" and replace with "(../images/" ??

2 Comments

Why? This seems and odd thing to do programmatically
It makes us curious.. probably, they would like to alter the images that will be displayed based on a theme.
0

PHP-CSS-Parser is a CSS parser written in PHP under the MIT license.

Comments

0

You must use regex to parse css correctly

regex to parse your code  :  '/(url)\s*\(\s*[\w\W]+\)/ms'

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.