开发者

Is there a PHP port of Java's Matcher class?

开发者 https://www.devze.com 2023-04-13 01:06 出处:网络
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_replac

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 d开发者_Python百科rastically changes the program flow).

So, has anyone ported Matcher to PHP?


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
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号