读取另一个PHP文件中的回显输出 [英] Read echo'ed output from another PHP file

查看:385
本文介绍了读取另一个PHP文件中的回显输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望1个PHP文件在同一服务器上运行"(包括?)另一个PHP文件,并以字符串形式访问其回显输出.

I want 1 PHP file to "run" (include?) another PHP file on the same server, and access its echo'ed output as a string.

如何在PHP中做到这一点?有内置功能可以做到这一点吗?

How do i do this in PHP? Any inbuilt functions to do this?

还是执行另一个PHP文件并获取其输出的更好方法?

Or any better way of executing another PHP file and getting its output?

推荐答案

您可以使用PHP的

You can use PHP's output buffering to accomplish this:

ob_start(); // begin collecting output

include 'myfile.php';

$result = ob_get_clean(); // retrieve output from myfile.php, stop buffering

$result将包含文本.

这篇关于读取另一个PHP文件中的回显输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆