2

我正在将 YUI 的CssCompressor移植到 PHP ,它有多个Matcher用途。为了长期维护,我希望 PHP 端口尽可能与 Java 原始端口相似(preg_replace_callback当然可以,但会极大地改变程序流程)。

那么,有没有人将 Matcher 移植到 PHP 中?

4

1 回答 1

1

您是否正在寻找while(find next match){ do stuff }PHP 中的等价物(不使用preg_match_all)?

在这种情况下preg_match,与 offset 参数一起使用。例如:

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

    // do stuff
}
于 2012-03-22T06:17:32.053 回答