在.php页面上将{{}转换为echo
如何将字符在.php页面上将{{}转换为echo,php,laravel-blade,Php,Laravel Blade,如何将字符{{}更改为.php页面上的等效回显函数,这与Laravel的blade.php页面非常相似(如果可能的话) 我环顾四周,发现唯一一个类似的问题是“如何在没有拉维尔的情况下使用拉维尔的刀片”,这不是我想要的 编辑 我发布这些新数据是因为apokryfos的回答 这是我正在运行的函数: function View($view) { $src = __DIR__.'/../../views/'.$view.'.view.php'; $destination= __DIR__
{{}
更改为.php
页面上的等效回显函数,这与Laravel的blade.php
页面非常相似(如果可能的话)
我环顾四周,发现唯一一个类似的问题是“如何在没有拉维尔的情况下使用拉维尔的刀片”,这不是我想要的
编辑
我发布这些新数据是因为apokryfos的回答
这是我正在运行的函数:
function View($view)
{
$src = __DIR__.'/../../views/'.$view.'.view.php';
$destination= __DIR__.'/../../views/'.$view.'.view.php';
file_put_contents(
$destination,
str_replace(["{{","}}" ],[ "<?=", "?>" ], file_get_contents($src))
);
echo file_get_contents($destination);
}
它发布一个php变量是
,然后页面上什么都没有,不知道为什么。您可以使用这个:
<?= $var ?>
这与:
<?php echo $var ?>
简单的做法是:
$src = "sourcefile.php";
$destination= "compiledsourcefile.php";
file_put_contents(
$destination,
str_replace(["{{","}}" ],[ "<?=", "?>" ], file_get_contents($src))
);
include $destination;
$src=“sourcefile.php”;
$destination=“compiledsourcefile.php”;
文件内容(
$destination,
str_replace([“{{,“}}”],[”“],file_get_contents($src))
);
包括$destination;
要直接回应此问题,请执行以下操作:
$src = "sourcefile.php";
$text = str_replace(["{{","}}" ],[ "<?=", "?>" ], file_get_contents($src))
eval("?>".$text); //Things get a bit ugly here
echo $text;
$src=“sourcefile.php”;
$text=str_replace([“{{,“}}”],[”“],file_get_contents($src))
eval(“?>”$text)//这里的情况有点糟糕
echo$文本;
之所以使用“?>”
,是因为eval在默认情况下以“PHP模式”启动,但正确编写的PHP文件将明确设置需要进入PHP模式的区域,并在默认情况下以HTML模式启动
注意:大多数人会说使用
eval
是不好的,虽然我同意使用eval
取消选中确实是不好的,但在从您编写的PHP文件中读取的代码上使用它与在没有那么坏的文件上使用include
完全相同。打开刀片源代码,看看吧?这真的很有趣,我从来没有想过这样使用PHP:)谢谢你,我收到了一个错误文件\u put\u contents***打开流失败:*路径/行号*
中没有错误。我的src和目的地是一样的,这会导致任何问题吗?@YasminFrench My bad,争论的方式是错误的谢谢,我认为我使用它的方式是错误的?如果是这样,我必须更改代码的功能,我更新了我的question@YasminFrench检查我的更新。它变得有点难看,但它仍然是刀片用来做内部(在版本3)现在它更复杂。
$src = "sourcefile.php";
$text = str_replace(["{{","}}" ],[ "<?=", "?>" ], file_get_contents($src))
eval("?>".$text); //Things get a bit ugly here
echo $text;