如何从file_get_contents或函数中的文件运行php代码 [英] How to run php code from file_get_contents or file in a function
问题描述
如何通过PHP函数运行一个代表某些源代码的字符串(<?,<?php,?>和等等)作为PHP? Eval不会把我的< ?标志(我读这个函数是由于某种原因废话)。
您可以执行PHP代码,并收集输出这个:
ob_start();
包含template.phtml;
$ out1 = ob_get_clean();
http://www.php.net/manual/de/function.ob-get-contents.php
I am designing my own MVC pattern to ease the process of creating homepages. My templating system needs my controller class to output my views. This means I have to output the file through a php function. I have been searching for some a while now and can't seem to find a solution.
How can I, through a PHP function, run a string representing some source code ("< ?", "< ?php", "? >" and so on) as php? Eval would not take my < ? signs (and I read that function is crap for some reason).
You could execute the php code and collect the output like this:
ob_start();
include "template.phtml";
$out1 = ob_get_clean();
http://www.php.net/manual/de/function.ob-get-contents.php
这篇关于如何从file_get_contents或函数中的文件运行php代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!