如何将PHP脚本**结果**包含在另一个PHP脚本中? [英] How can I get a PHP script **results** included into another PHP script?

查看:112
本文介绍了如何将PHP脚本**结果**包含在另一个PHP脚本中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将给定脚本的结果(比方说a.php)包含在另一个脚本中(比方说b.php)。

I'd like to include the results of a given script (let's say a.php) into another script (let's say b.php).

虽然有PHP include语句和其他对应语句(include_once,require和require_once),但似乎所有这些都包含文件内容而不是其处理结果我希望。

Although there is the PHP include statement and their other counterparts (include_once, require and require_once), it seems all of them include the file contents instead of its processing results as I would expect.

那么如何首先处理a.php然后将其结果(而不是文件内容本身)包含在b.php脚本中呢?

So how can I get a.php processed first and then include its results (not the file contents itself) into b.php script ?

另一方面,如果我的包含文件(a.php)有一个return语句,那么整个文件应该首先处理,或者它的内容也包含在b.php中是吗?

On the other hand, if my included file (a.php) has a return statement, is the entire file expected to be processed first or its contents are also included into b.php as is ?

提前感谢您的回复。

推荐答案

a .php:

<?php
echo "world";

b.php:

<?php
ob_start();
include("a.php");
$a= ob_get_clean();
echo "Hello, $a!";  

也许?

这篇关于如何将PHP脚本**结果**包含在另一个PHP脚本中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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