How can I replace braces with <?php ?> in php file?

后端 未结 3 2034
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-29 16:01

I wanna replace braces with in a file with php extension. I have a class as a library and in this class I have three function like these:

         


        
3条回答
  •  暖寄归人
    2021-01-29 16:31

    do this:

    function parser($view,$data)
    {
        $data=array("data"=>$data);
        $template=file_get_contents(APP_DIR.DS.'view'.DS.$view.'.php');
        $replace = array();
        foreach ($data as $key => $value) {
            #if $data is array...
            $replace = array_merge(
                $replace,array("{".$key."}"=>$value)
                );
        }
    
        $template=strtr($template,$replace);
        echo $template;
    }
    

    and ignore other two functions.

提交回复
热议问题