CSS parser using PHP

2020-02-15 06:33发布

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

标签: php css parsing
5条回答
beautiful°
3楼-- · 2020-02-15 06:41
$css = str_replace("url(images/", "url(../images/", $css);
查看更多
乱世女痞
4楼-- · 2020-02-15 06:44

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

查看更多
We Are One
5楼-- · 2020-02-15 06:48

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

查看更多
Lonely孤独者°
6楼-- · 2020-02-15 06:52

You must use regex to parse css correctly

regex to parse your code  :  '/(url)\s*\(\s*[\w\W]+\)/ms'
查看更多
登录 后发表回答