2

I'm porting YUI's CssCompressor, which has several Matcher uses, to PHP. For the sake of long-term maintenance I'd like to keep the PHP port as similar to the Java original as possible (preg_replace_callback of course works, but drastically changes the program flow).

So, has anyone ported Matcher to PHP?

VLAZ
  • 26,331
  • 9
  • 49
  • 67
Steve Clay
  • 8,671
  • 2
  • 42
  • 48
  • 1
    Why wouldn't you just use `YUICompressor.php`? http://code.google.com/p/minify/source/browse/trunk/min/lib/Minify/YUICompressor.php Writing your own port sounds like a maintenance headache. – Matt Ball Oct 15 '11 at 18:57
  • @MattBall because that's a wrapper for Java, which is commonly not available on shared hosting. – Steve Clay Oct 15 '11 at 19:14
  • Sounds like no one has - sounds like a fun project! – Nathan Loding Oct 18 '11 at 16:55

1 Answers1

1

Are you looking for the while(find next match){ do stuff } equivalent in PHP (without using preg_match_all)?

In that case use preg_match with the offset parameter. For example:

offset = 0;
while(preg_match(re, str, matches, PREG_OFFSET_CAPTURE, offset)){
    offset = matches[0][1] + strlen(matches[0][0]);

    // do stuff
}
Qtax
  • 33,241
  • 9
  • 83
  • 121
  • I'm already using this technique in [my own port](http://code.google.com/p/mrclay/source/browse/trunk/php/java/util/regex/Matcher.php), which isn't complete. – Steve Clay Mar 22 '12 at 18:02