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

后端 未结 3 2032
佛祖请我去吃肉
佛祖请我去吃肉 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:08

    What you're trying to do here won't work. The replacements carried out by the output buffering callback occur after PHP code has already been parsed and executed. Introducing new PHP code tags at this stage won't cause them to be executed.

    You will need to instead preprocess the PHP source file before evaluating it, e.g.

    $tp = file_get_contents(APP_DIR.DS.'view'.DS.$view.'.php');
    $tp = str_replace("{", "", $tp);
    eval($tp);
    

    However, I'd strongly recommend using an existing template engine; this approach will be inefficient and limited. You might want to give Twig a shot, for instance.

提交回复
热议问题