php - preg_replace out CSS comments? -


I am writing a quick preg_replace to strip comments from CSS This is the syntax usually used in CSS comments:

  / * development class * / / * comment for me for easy testing (this will make errors easier to see) * /  

I'm trying to kill everything between / * and * /:

  $ pattern = "# / \ * [^ (\ * /)] * \ * / # "; $ Place = ""; $ V = preg_replace ($ patterns, $ replaced, $ v);  

No dice! It seems that there is a mess on the forward slash because I can get it out of the pattern if I come out of the pattern. I have tried to look at a few simple patterns whether I could just lose a slash, but they returned the original strings unchanged:

"# / #"; $ Pattern = "/ \ //";

Any ideas why I can not match those slashes? Thanks!

Here's a solution:

  $ regex = array (" `^ ([\ T \ s] +)` ism '=> gt;' ',' `^ \ / \ * (. +?) \ * \ /` Ism '=> "", "` ( [\ N \ A;] +) \ / \ * (. +?) \ * \ / `Ism '= & gt;" $ 1 "," `([\ n \ a \\] +) // (. +?) [\ N \ r] `ism '= & gt;" $ 1 \ n "," `(^ [\ r \ n] * | [\ r \ n] +) [\ s \ t ] * [\ R \ N] + 'ism "= & gt;" \ n "); $ Buffer = pre_legal (array_kiz ($ regex), $ regex, $ buffer);  

View from script / stylesheet pre-processor in the minimal PHP framework

See:

csstest.php:

  & lt ;? Php $ buffer = file_get_contents ('test.css'); $ Regex = array ("` ^ ([\ t \ s] +) `ism '=> gt;' ',` `\ / \ * (. +?) \ * \ /' Ism '= & gt; "", "` ([\ N \ A;] +) \ / \ * (. +?) \ * \ / 'Ism' = & gt; "$ 1", "` ([\ n \ A; \ S] +) // (. +?) [\ N \ r] `ism '= & gt;" $ 1 \ n "," (^ [\ r \ n] * | [\ r \ n] +) [\ S \ t] * [\ r \ n] + 'ism "= & gt;" \ n "); $ Buffer = pre_legal (array_kiz ($ regex), $ regex, $ buffer); Buffer $ buffer; ? & Gt; Test to remove  

test.css:

  / * this * / .test {}  

Csstest.php:

  .test {}  

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -