woninana
woninana

Reputation: 3481

CSS parser using PHP

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...

Upvotes: 1

Views: 2008

Answers (5)

Mahdi Shad
Mahdi Shad

Reputation: 1447

You must use regex to parse css correctly

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

Upvotes: 0

hakre
hakre

Reputation: 197564

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

Upvotes: 0

diagonalbatman
diagonalbatman

Reputation: 17982

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

Upvotes: 0

Dan Grossman
Dan Grossman

Reputation: 52372

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

Upvotes: 4

Related Questions