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

关于php中str_replace的有关问题

WBOY
WBOYOriginal
2016-06-13 12:22:541150browse

关于php中str_replace的问题
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() {<br />  ob_start();<br />  eval('?>' . $this->content);<br />  $this->content = ob_get_clean();<br />}<br />

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