请大家帮帮我preg_replace_callback替换问题,美优相册,php5.6

一个人的牢骚 2016-04-17 01:45:34
原代码:
        $str = preg_replace("/\{(\\$[a-zA-Z0-9_\[\]\'\"\$\x7f-\xff]+)\}/es", "\$this->addquote('<?php echo \\1;?>')",$str);
$str = preg_replace ( "/\{([A-Z_\x7f-\xff][A-Z0-9_\x7f-\xff]*)\}/s", "<?php echo \\1;?>", $str );
$str = preg_replace("/\{link(\s+.+?)\}/ies", "\$this->striplink('\\1')", $str);
$str = preg_replace("/\{lang\s+(.+?)\}/ies", "\$this->striplang('\\1')",$str);
$str = preg_replace("/\{img\s+(.+?)\}/is", "<?php echo img_path(\\1);?>",$str);
$str = preg_replace("/\{mp:(\w+)(\s+[^}]+)\}/ie", "\$this->mp_tag('\\1','\\2', '\\0')", $str);
$str = preg_replace("/\{\/mp\}/ie", "\$this->end_mp_tag()", $str);
$str = preg_replace("/\{filter:(\w+)(\s+.+?)\}/ie","\$this->do_filter('\\1','\\2')",$str);
$str = preg_replace("/\{thumbimg(\s+.+?)\}/ies","\$this->makethumbpath('\\1')",$str);

改了代码后不报错了,但是所有的标题和文本便签全部显示代码,下面贴出修改后的代码:
$str = preg_replace_callback("/\{(\\$[a-zA-Z0-9_\[\]\'\"\$\x7f-\xff]+)\}/s",function($r){ return $this->addquote("<?php echo $r[1]?>"); }, $str);
$str = preg_replace_callback("/\{([A-Z_\x7f-\xff][A-Z0-9_\x7f-\xff]*)\}/s",function($r){ return "<?php echo $r[1]?>"; }, $str);
$str = preg_replace_callback("/\{link(\s+.+?)\}/is",function($r){ return $this->striplink('$r[1]'); }, $str);
$str = preg_replace_callback("/\{lang\s+(.+?)\}/is",function($r){ return $this->striplang('$r[1]'); }, $str);
$str = preg_replace_callback("/\{mp:(\w+)(\s+[^}]+)\}/i",function($r){ return $this->mp_tag($r[1],$r[2],$r[3]); }, $str);
$str = preg_replace_callback("/\{\/mp\}/i",function($r){ return $this->end_mp_tag($r[1]); }, $str);
$str = preg_replace_callback("/\{filter:(\w+)(\s+.+?)\}/i",function($r){ return $this->do_filter($r[1],$r[2]); }, $str);
$str = preg_replace_callback("/\{thumbimg(\s+.+?)\}/is",function($r){ return $this->makethumbpath($r[1]);}, $str);

附图:
...全文
154 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuzuning 2016-04-17
  • 打赏
  • 举报
回复
看上去没有问题 你可将处理前后的串对比一下
一个人的牢骚 2016-04-17
  • 打赏
  • 举报
回复
引用 2 楼 xuzuning 的回复:
看上去没有问题 你可将处理前后的串对比一下
我贴一个处理前台代码,帮看下,谢谢:
function index(){
        need_login('page');
        
        $site = $this->setting->get_conf('site');
        $site['description'] = safe_invert($site['description']);
        $site['footer'] = safe_invert($site['footer'],true);
        $site['share_title'] = safe_invert($site['share_title']);
        $this->output->set('site',$site);
        $this->output->set('enable_comment',$this->setting->get_conf('system.enable_comment'));
        $this->output->set('enable_comment_captcha',$this->setting->get_conf('system.enable_comment_captcha'));
        $this->output->set('enable_login_captcha',$this->setting->get_conf('system.enable_login_captcha'));
        $this->output->set('comment_audit',$this->setting->get_conf('system.comment_audit'));

        $this->output->set('enable_auto_update',$this->setting->get_conf('system.enable_auto_update'));
        $this->output->set('show_process_info',$this->setting->get_conf('system.show_process_info'));
        $this->output->set('gravatar_url',$this->setting->get_conf('system.gravatar_url'));
        
        //面包屑
        $crumb_nav = array();
        $crumb_nav[] = array('name'=>lang('system_setting'),'link'=>site_link('setting'));
        $crumb_nav[] = array('name'=>lang('basic_setting'));
        
        $this->page_crumb($crumb_nav);
        
        $page_title = lang('basic_setting').' - '.lang('system_setting').' - '.$this->setting->get_conf('site.title');
        $page_keywords = $this->setting->get_conf('site.keywords');
        $page_description = $this->setting->get_conf('site.description');
        
        $this->page_init($page_title,$page_keywords,$page_description);
        $this->render();
    }
    
    function save_basic(){
        need_login('ajax_box');
        
        $site = $this->getPost('site');
        $site['title'] = safe_convert($site['title']);
        $site['url'] = safe_convert($site['url']);
        $site['keywords'] = safe_convert($site['keywords']);
        $site['description'] = safe_convert($site['description']);
        $site['share_title'] = safe_convert($site['share_title']);
        
        $gravatar_url = safe_convert($this->getPost('gravatar_url'));
        
        if($site['title'] == ''){
            form_ajax_failed('box',lang('empty_site_name'));
        }
        if($site['url'] == ''){
            form_ajax_failed('box',lang('empty_site_url'));
        }
        $this->setting->set_conf('site.title',$site['title']);
        $this->setting->set_conf('site.url',$site['url']);
        $this->setting->set_conf('site.keywords',$site['keywords']);
        $this->setting->set_conf('site.description',$site['description']);
        $this->setting->set_conf('site.share_title',$site['share_title']);
        $this->setting->set_conf('system.gravatar_url',$gravatar_url);
        $this->setting->set_conf('system.comment_audit',intval($this->getPost('comment_audit')));

        if($this->getPost('enable_comment')){
            $this->setting->set_conf('system.enable_comment',true);
        }else{
            $this->setting->set_conf('system.enable_comment',false);
        }

        if($this->getPost('enable_comment_captcha')){
            $this->setting->set_conf('system.enable_comment_captcha',true);
        }else{
            $this->setting->set_conf('system.enable_comment_captcha',false);
        }

        if($this->getPost('enable_login_captcha')){
            $this->setting->set_conf('system.enable_login_captcha',true);
        }else{
            $this->setting->set_conf('system.enable_login_captcha',false);
        }
        
        if($this->getPost('enable_auto_update')){
            $this->setting->set_conf('system.enable_auto_update',true);
        }else{
            $this->setting->set_conf('system.enable_auto_update',false);
        }

        
        form_ajax_success('box',lang('save_setting_success'),null,0.5,$_SERVER['HTTP_REFERER']);
    }
    
一个人的牢骚 2016-04-17
  • 打赏
  • 举报
回复
自己又捣鼓一阵还是不行,上面修改的和下面修改的都是一个效果 /** * 解析模板 * * @param $str 模板内容 * @return ture */ function template_parse($str) { $str = preg_replace("/\<\!\-\-\{(.+?)\}\-\-\>/s", "{\\1}", $str); $str = str_replace("{LF}", "<?php echo \"\\n\"; ?>", $str); $str = preg_replace ( "/\{template\s+(.+)\}/", "<?php include \$this->template(\"\\1\"); ?>",$str); $str = preg_replace ( "/\{include\s+(.+)\}/", "<?php include \\1; ?>", $str ); $str = preg_replace ( "/\{php\s+(.+)\}/", "<?php \\1?>", $str ); $str = preg_replace ( "/\{echo\s+(.+?)\}/", "<?php echo \\1; ?>", $str); $str = preg_replace ( "/\{if\s+(.+?)\}/", "<?php if(\\1) { ?>", $str ); $str = preg_replace ( "/\{else\}/", "<?php } else { ?>", $str ); $str = preg_replace ( "/\{elseif\s+(.+?)\}/", "<?php } elseif (\\1) { ?>", $str ); $str = preg_replace ( "/\{\/if\}/", "<?php } ?>", $str ); //for 循环 $str = preg_replace("/\{for\s+(.+?)\}/","<?php for(\\1) { ?>",$str); $str = preg_replace("/\{\/for\}/","<?php } ?>",$str); //++ -- $str = preg_replace("/\{\+\+(.+?)\}/","<?php ++\\1; ?>",$str); $str = preg_replace("/\{\-\-(.+?)\}/","<?php --\\1; ?>",$str); $str = preg_replace("/\{(.+?)\+\+\}/","<?php \\1++; ?>",$str); $str = preg_replace("/\{(.+?)\-\-\}/","<?php \\1--; ?>",$str); $str = preg_replace ( "/\{loop\s+(\S+)\s+(\S+)\}/", "<?php if(is_array(\\1)) foreach(\\1 AS \\2) { ?>", $str ); $str = preg_replace ( "/\{loop\s+(\S+)\s+(\S+)\s+(\S+)\}/", "<?php if(is_array(\\1)) foreach(\\1 AS \\2 => \\3) { ?>", $str ); $str = preg_replace ( "/\{\/loop\}/", "<?php } ?>", $str ); $str = preg_replace ( "/\{([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff:]*\(([^{}]*)\))\}/", "<?php echo \\1;?>", $str ); $str = preg_replace ( "/\{\\$([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff:]*\(([^{}]*)\))\}/", "<?php echo \\1;?>", $str ); $str = preg_replace ( "/\{(\\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\}/", "<?php echo \\1;?>", $str ); $str = preg_replace("/\{img\s+(.+?)\}/is", "<?php echo img_path(\\1);?>",$str); $str = preg_replace_callback("/\{(\\$[a-zA-Z0-9_\[\]\'\"\$\x7f-\xff]+)\}/s",function($r){ return "<?php echo $r[1]?>"; }, $str); $str = preg_replace_callback("/\{([A-Z_\x7f-\xff][A-Z0-9_\x7f-\xff]*)\}/s",function($r){ return "<?php echo $r[1]?>"; }, $str); $str = preg_replace_callback("/\{link(\s+.+?)\}/is",function($r){ return $r[1]; }, $str); $str = preg_replace_callback("/\{lang\s+(.+?)\}/is",function($r){ return $r[1]; }, $str); $str = preg_replace_callback("/\{mp:(\w+)(\s+[^}]+)\}/i",function($r){ return $r[1].$r[2].$r[3]; }, $str); $str = preg_replace_callback("/\{\/mp\}/i",function($r){ return $r[1]; }, $str); $str = preg_replace_callback("/\{filter:(\w+)(\s+.+?)\}/i",function($r){ return $r[1].$r[2]; }, $str); $str = preg_replace_callback("/\{thumbimg(\s+.+?)\}/is",function($r){ return $r[1];}, $str); $str = "<?php if(!defined('IN_MEIU')) exit('Access Denied'); ?>" . $str; return $str; }

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧