Carlos Carlos - 6 months ago 45
PHP Question

Remove comments from css file

I have to read a css file and remove its commentaries, so i've decided to use the

function from php:

$original = '
.test, input[type="text"]{ color: blue; }

/* bar */
text-decoration: underline;
color: red;
background: #FFF;

echo preg_replace('/\/\*.*\*\//s', '', $original);

the problem is that its losing the line
.test, input[type="text"]{ color: blue; }

Answer Source

Change .* to .*?.

echo preg_replace('#/\*.*?\*/#s', '', $original);

This will only remove /* up to the closest */ rather than the furthest.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download