$str = preg_replace("/\{(\\$[a-zA-Z0-9_\[\]\'\"\$\x7f-\xff]+)\}/es", "\$this->addquote('<?php echo \\1;?>')",$str);$str = preg_replace("/\{pc:(\w+)\s+([^}]+)\}/ie", "self::pc_tag('$1','$2', '$0')", $str);第一个里面有<?php echo \\1;?> 请问应该如何修改!改了几次都报错第二个也是好像变量传递不过去新手上路

解决方案 »

  1.   

    做模版解析吧$this->addquote()  //别忘了这个也是php代码!
    换句话说 你的会不会解析成这样<?php<?php
    echo 1;
    ?>?>
      

  2.   

    第一个自己搞定了!不是自己没写对,是没更新缓存[code=php$str = preg_replace_callback("/\{(\\$[a-zA-Z0-9_\[\]\'\"\$\x7f-\xff]+)\}/s",
    function ($r) {
                            return $this->addquote("<?php echo $r[1]; ?>");
                          },$str);][/code]上面这个已经通过测试了!
      

  3.   

    $str = preg_replace_callback("/\{(\\$[a-zA-Z0-9_\[\]\'\"\$\x7f-\xff]+)\}/s",
    function ($r) {
                            return $this->addquote("<?php echo $r[1]; ?>");
                          },$str);竟然不能修改自己的帖子。
      

  4.   

    $str = preg_replace_callback("/\{pc:(\w+)\s+([^}]+)\}/i", array('A', 'pc_tag'), $str);  // A 替换为你的类名你的pc_tag方法也要改下了,原来有三个参数,要改为一个参数。
    比如 
    public static function pc_tag($m) {
        然后 $m[1] , $m[2] , $m[0] 分别对应你原来的三个参数。
    }
      

  5.   

    $str = preg_replace("/\{pc:(\w+)\s+([^}]+)\}/ie", "self::pc_tag('$1','$2', '$0')", $str);
    要改为
    $str = preg_replace("/\{pc:(\w+)\s+([^}]+)\}/i", function($r) { return self::pc_tag($r[1],$r[2], $r[0]); }, $str);