[英]getting data from php variable
$content = file_get_contents('file.php'); $ content = file_get_contents('file.php');
echo $content; echo $ content;
nothing displays, expect when displaying the page sourcecode in browser the display is this 没有任何显示,期望在浏览器中显示页面源代码时显示为此
<? foreach(glob("folder/*.php") as $class_filename) { require_once($class_filename); } ?>
so it wont execute the script when getting the content.. 所以它在获取内容时不会执行脚本..
file.php contains this code <? foreach(glob("folder/*.php") as $class_filename) { require_once($class_filename); } ?>
file.php包含此代码
<? foreach(glob("folder/*.php") as $class_filename) { require_once($class_filename); } ?>
<? foreach(glob("folder/*.php") as $class_filename) { require_once($class_filename); } ?>
and if I do next 如果我做下一个
$content = foreach(glob("folder/*.php") as $class_filename) { require_once($class_filename); } ?>
it complains about unexpected foreach... 它抱怨意外的预告......
is there a way to read the folder/ .php files content to single $variable and then echo/print all folder/ .php files to page where it should be? 有没有办法将文件夹/ .php文件内容读取到单个$ variable,然后回显/打印所有文件夹/ .php文件到它应该的页面?
thanks for help already. 谢谢你的帮助。
Is that what you want to do ? 那是你想做的吗?
$content = '';
foreach (glob('folder/*.php') as $class){$content .= file_get_contents($class);}
echo $content;
What you're trying won't execute the contents of the "file.php", jsut display the contents of them on screen. 你正在尝试的不会执行“file.php”的内容,jsut会在屏幕上显示它们的内容。
If you want to execute file.php, use eval ($content)
如果要执行file.php,请使用
eval ($content)
To capture the output, use something like: 要捕获输出,请使用以下内容:
ob_start(); // Don't echo anything but buffer it up
$codeToRun=file_get_contents('file.php'); // Get the contents of file.php
eval ($codeToRun); // Run the contents of file.php
$content=ob_get_flush(); // Dump anything that should have been echoed to a variable and stop buffering
echo $content; //echo the stuff that should have been echoed above
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.