q17816101
Soot0927
2016-11-30 05:44

preg_replace 改 preg_replace_callback 请大神帮忙

  • 函数

preg_replace /e 怎么换成preg_replace_callback

     public function parseTagLib($tagLib,&$content,$hide=false) {
        $begin      =   $this->config['taglib_begin'];
        $end        =   $this->config['taglib_end'];
        $className  =   'TagLib'.ucwords($tagLib);
        $tLib       =   Think::instance($className);
        foreach ($tLib->getTags() as $name=>$val){
            $tags = array($name);
            if(isset($val['alias'])) {// 别名设置
                $tags       = explode(',',$val['alias']);
                $tags[]     =  $name;
            }
            $level      =   isset($val['level'])?$val['level']:1;
            $closeTag   =   isset($val['close'])?$val['close']:true;
            foreach ($tags as $tag){
                $parseTag = !$hide? $tagLib.':'.$tag: $tag;// 实际要解析的标签名称
                if(!method_exists($tLib,'_'.$tag)) {
                    // 别名可以无需定义解析方法
                    $tag  =  $name;
                }
                $n1 = empty($val['attr'])?'(\s*?)':'\s([^'.$end.']*)';
                if (!$closeTag){
                    $patterns       = '/'.$begin.$parseTag.$n1.'\/(\s*?)'.$end.'/eis';//这句
                    $replacement    = "\$this->parseXmlTag('$tagLib','$tag','$1','')";
                    $content        = preg_replace($patterns, $replacement,$content);
                }else{
                    $patterns       = '/'.$begin.$parseTag.$n1.$end.'(.*?)'.$begin.'\/'.$parseTag.'(\s*?)'.$end.'/eis';//这句
                    $replacement    = "\$this->parseXmlTag('$tagLib','$tag','$1','$2')";
                    for($i=0;$i<$level;$i++) 
                        $content=preg_replace($patterns,$replacement,$content);
                }
            }
        }
    }
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答