0

Very very long story short, I am basically trying to use a regex (or maybe even string replace) to change

@import url('narf.css');

to

<?php include('narf.css'); ?>

So far, I have come up with this, BUT it does not close the PHP tag....

$var =  str_replace('@import url', '<?php include', $var);

Aside from this, I am kinda stuck. I am HORRIBLE at regex syntax and everything I have tried or tried to look up has lead me down a dead end road.

Any help would be MORE than appreciated.

4

1 に答える 1

2
$var = preg_replace('/@import url\(([^)]+)\);/', '<?php include $1; ?>', $var);

To break it down:

  1. @import url\( - literally matches @import url(.
  2. ([^)]+) - Captures everything inside the parenthesis into the first back-reference.
  3. \); - literally matches );.

If you have some whitespace somewhere in there, you's have to account for that too...

于 2012-08-28T01:48:58.937 に答える