美文网首页
PHP升级之preg_replace转preg_replace_

PHP升级之preg_replace转preg_replace_

作者: 飞雪连天_4378 | 来源:发表于2019-05-15 18:20 被阅读0次

    1,原来://变量标签

    /* $this->content = preg_replace ("/\{$stag:([a-zA-Z_0-9\[\]\'\"\$\x7f-\xff\+\-\*\/]+)\}/es",

    "\$this->addquote('<?php echo \\1; ?>')",$this->content);*/

    现在:$this->content = preg_replace_callback(

                "/\{$stag:([a-zA-Z_0-9\[\]\'\"\$\x7f-\xff\+\-\*\/]+)\}/",

                function ($matches){  return $this->addquote('<?php echo '.$matches[1].'; ?>');},$this->content);

    2,原来:/* $this->content = preg_replace ("/\{$stag:(\\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)([\$a-zA-Z_0-9\[\]\'\"\$\x7f-\xff]+)\}/es",

    "\$this->addquote('<?php echo \\1\\2; ?>')",$this->content);*/

    现在:$this->content = preg_replace_callback(

                "/\{$stag:(\\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\s*([\+\-\*\/])\s*(\\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\}/",

                function ($matches){  return $this->addquote('<?php echo '.$matches[1].$matches[2].'; ?>');},$this->content);

    3, //保留标签

    原来:/* $this->content = preg_replace ( "/\{$stag:(\w+)\s+([^}]+)\}/ie", "self::pc_tag_html('$1','$2', '$0')", $this->content);*/

    现在:$this->content = preg_replace_callback(

                "/\{$stag:(\w+)\s+([^}]+)\}/",

                function ($matches){  return self::pc_tag_html($matches[1],$matches[2], $matches[0]);},$this->content);

    //模块调用标签

    4,原来:/* $this->content = preg_replace ( "/\{$stag:m=(\w+) mod=[\"|\'](\w+)[\"|\']([^}]+)\}/ie", "self::pc_module_tag('$1','$2', '$3')", $this->content); */

    现在:$this->content = preg_replace_callback(

                "/\{$stag:m=(\w+) mod=[\"|\'](\w+)[\"|\']([^}]+)\}/",

                function ($matches){  return self::pc_module_tag($matches[1],$matches[2], $matches[3]);},$this->content);

    相关文章

      网友评论

          本文标题:PHP升级之preg_replace转preg_replace_

          本文链接:https://www.haomeiwen.com/subject/xlbplxtx.html