如何用 <?php ?> 替换大括号在 php 文件中? [英] How can I replace braces with <?php ?> in php file?

查看:50
本文介绍了如何用 <?php ?> 替换大括号在 php 文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用 <?php ?> 替换带有 php 扩展名的文件中的大括号.我有一个类作为库,在这个类中我有三个这样的函数:

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

 function replace_left_delimeter($buffer)
{
    return($this->replace_right_delimeter(str_replace("{", "<?php echo $", $buffer)));
}

function replace_right_delimeter($buffer)
{
    return(str_replace("}", "; ?> ", $buffer));
}

function parser($view,$data)
{
    ob_start(array($this,"replace_left_delimeter"));
    include APP_DIR.DS.'view'.DS.$view.'.php';
    ob_end_flush();
}

我有一个带有 php 扩展名的视图文件,如下所示:

and I have a view file with php extension like this:

{tmp} tmpstr

在输出中我只保存 tmpstr 并且在浏览器中的源代码中我得到

in output I save just tmpstr and in source code in browser I get

<?php echo $tmp; ?> 
tmpstr

在包含文件 中显示为