本帖最后由 MoontoC 于 2011-06-23 12:14:37 编辑

解决方案 »

  1.   


    preg_match('/<\w (\w+), (\w+), (\w+), (\w+)>/i', $in, $matches);
    var_dump($matches);
      

  2.   

    $in = '<x xx, x1, x2, x3>';
    preg_match_all('/(\w+){2,}/i', $in, $matches);
    var_dump($matches[0]);array(4) {
      [0]=>
      string(2) "xx"
      [1]=>
      string(2) "x1"
      [2]=>
      string(2) "x2"
      [3]=>
      string(2) "x3"
    }
      

  3.   


    $str = <<<TEXT
    <x xx, x1, x2, x3>
    TEXT;preg_match_all('#([a-z\d]+,?)+#i', $str, $matches);
    echo '<pre>';var_dump($matches[1]);
    /*
    输出结果:
    array(5) {
      [0]=>
      string(1) "x"
      [1]=>
      string(3) "xx,"
      [2]=>
      string(3) "x1,"
      [3]=>
      string(3) "x2,"
      [4]=>
      string(2) "x3"
    }
    */
      

  4.   

    感谢楼上两位的preg_match_all结果, 虽然是有效, 但没办法对应我的实际情况, 我并不是就像匹配一堆东西里面用逗号分隔的一坨, 而是<tag xxx, xxx, xxx>标签是固定的, 并且有多个不同类型, 不同语法的tag然后还要$rules = '#\{' . join( '\}|\{', $rules ) . '\}#i';最后用preg_replace_callback来连续处理多个tag内容, 所以没办法使用_all, 上面的例子, 我可能说的不全面吧_-