繁体   English   中英

从php变量获取数据

[英]getting data from php variable

$ content = file_get_contents('file.php');

echo $ content;

没有任何显示,期望在浏览器中显示页面源代码时显示为此

<? 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); } ?>

如果我做下一个

$content = foreach(glob("folder/*.php") as $class_filename) { require_once($class_filename); } ?>

它抱怨意外的预告......

有没有办法将文件夹/ .php文件内容读取到单个$ variable,然后回显/打印所有文件夹/ .php文件到它应该的页面?

谢谢你的帮助。

那是你想做的吗?

$content = '';
foreach (glob('folder/*.php') as $class){$content .= file_get_contents($class);}
echo $content;

你正在尝试的不会执行“file.php”的内容,jsut会在屏幕上显示它们的内容。

如果要执行file.php,请使用eval ($content)

要捕获输出,请使用以下内容:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM