Home >Backend Development >PHP Tutorial >关于php中str_replace的问题

关于php中str_replace的问题

WBOY
WBOYOriginal
2016-06-23 13:30:54874browse

public function display(){
        ob_start();
        if(preg_match_all('/(?)/s',$this->content,$match)){
            $find = $match[1];
            $_replace = array();
            foreach($match[2] as $_match){
                eval($_match);
                $_replace[] = ob_get_contents();
                ob_clean();
            }
            ob_flush();
            str_replace($find,$_replace,$this->content,$i);
        }
        header('Content-type:text/html;charset=UTF-8');
        var_dump($this->content);
        var_dump($match[1]);
        var_dump($i);
        ob_end_flush();
    }

我写了一段解析模板的代码,如上;现在执行之后出现了像下面图片上显示的结果, ,看图上显示应该是已经匹配到了字符串,但是为什么之后显示的结果却不是replace数组中的值呢


回复讨论(解决方案)

如果你希望我们帮你调试,那么请给出测试数据

你的这段代码只需这样就可以了

public function display() {  ob_start();  eval('?>' . $this->content);  $this->content = ob_get_clean();}

谢谢,我照着改了之后直接就显示了,原理还没怎么明白,我再研究研究

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn