Hey. I'm trying to parse a CSS file using PHP.
I'm trying to run this expression:
"/(". $selector . "\\s*{[\\w\\s:\\-;()#]*)(" . $property . ":)([^;}]+)(}?)/Ui"
This regex is supposed to pin down a specific property within a selector and allow me to change it's value/remove it.
rational:
- match the selector and it's text preceding to the property
- match the property name
- match the property value
- if the value ends by the } sign - catch it as well
The broken bit is #3 - For some unknown reason, when I run this through preg_match, the value group(#3) only catches the first char.
For example, running this expression:
preg_replace("/(h1\s*{[\w\s:\-;()#]*)(font-size:)(([^;}])+)(}?)/Ui","$1 $4",$css);
(find the font-size property of the h1 selector, and remove the property and value)
on this css group:
h1{
background:#fff;
font-size:10px;
text-align:underline;
color:#abc;
}
I get:
h1{
background:#fff;
/* note that although the property was matched and removed,
the value only matched the 1st char: 1 */
0px;
text-align:underline;
color:#abc;
}
I've tried to check the expression through some test tools and it worked fine, so I'm guessing this is a preg* specific problem.
any ideas what I'm doing wrong?