包含文件并获取变量,但不包含内容
include file and get variables, but not content
我有一个从 XML.
获取内容的文件
ob_start();
require_once 'feed.php';
$title = 'ExampleTitle';
foreach(Feed('example.url') as $f ) {
if (strpos($f->title, $title) !== false)
echo $f->description;
}
$output = ob_get_contents();
输出示例:
Currently 21*C and sunny.
我使用 ob_start();
和 $output = ob_get_contents();
将输出保存在一个变量中。
我想在另一个 PHP 文件中使用 $output
和其他变量。但是当我使用 include ('status.php');
将它包含在另一个 PHP 中时。它也输出结果。我只想访问变量,而不是文件来输出任何东西。
我目前正在使用输出的文件。所以不想改
希望你明白我的意思。非常感谢任何帮助!
你可以在会话中分配变量,然后你可以在你想要的任何页面中使用它。
即在你的 status.php
<?php
session_start();
#your codes
$output = ob_get_contents();
$_SESSION["output"] = $output; //Then use the session
?>
或者如果你必须包含,那么你将不得不隐藏污垢,在一个隐藏的标签中。
<div style="display:none;">
<?php include('status.php'); ?>
</div>
<?php echo $output; //here is your variable ?>
我有一个从 XML.
获取内容的文件ob_start();
require_once 'feed.php';
$title = 'ExampleTitle';
foreach(Feed('example.url') as $f ) {
if (strpos($f->title, $title) !== false)
echo $f->description;
}
$output = ob_get_contents();
输出示例:
Currently 21*C and sunny.
我使用 ob_start();
和 $output = ob_get_contents();
将输出保存在一个变量中。
我想在另一个 PHP 文件中使用 $output
和其他变量。但是当我使用 include ('status.php');
将它包含在另一个 PHP 中时。它也输出结果。我只想访问变量,而不是文件来输出任何东西。
我目前正在使用输出的文件。所以不想改
希望你明白我的意思。非常感谢任何帮助!
你可以在会话中分配变量,然后你可以在你想要的任何页面中使用它。
即在你的 status.php
<?php
session_start();
#your codes
$output = ob_get_contents();
$_SESSION["output"] = $output; //Then use the session
?>
或者如果你必须包含,那么你将不得不隐藏污垢,在一个隐藏的标签中。
<div style="display:none;">
<?php include('status.php'); ?>
</div>
<?php echo $output; //here is your variable ?>