Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将所有内容存储在一个变量中,而不是单独回显所有内容?_Php_Variables - Fatal编程技术网

Php 如何将所有内容存储在一个变量中,而不是单独回显所有内容?

Php 如何将所有内容存储在一个变量中,而不是单独回显所有内容?,php,variables,Php,Variables,请参阅: 我是php新手,正在编辑ventrilo状态脚本。我希望它将所有内容存储在一个大变量中,以便于解析,而不是使用单独的echo。有人能告诉我怎样才能做到这一点吗 谢谢 Dennis您可以使用并获取其内容: ob_start(); echo 'foobar'; $contents = ob_get_contents(); // now contains 'foobar' ob_end_clean(); 您可以使用并获取其内容: ob_start(); echo 'foobar'; $c

请参阅:

我是php新手,正在编辑ventrilo状态脚本。我希望它将所有内容存储在一个大变量中,以便于解析,而不是使用单独的echo。有人能告诉我怎样才能做到这一点吗

谢谢

Dennis

您可以使用并获取其内容:

ob_start();
echo 'foobar';
$contents = ob_get_contents();  // now contains 'foobar'
ob_end_clean();
您可以使用并获取其内容:

ob_start();
echo 'foobar';
$contents = ob_get_contents();  // now contains 'foobar'
ob_end_clean();

在开头声明一个变量,比如$data或其他。然后,更换回显呼叫:

echo "hello";
为此:

$data .= "hello";

然后在函数末尾返回$data变量

在开头声明一个变量,比如$data或其他什么。然后,更换回显呼叫:

echo "hello";
为此:

$data .= "hello";

然后在函数末尾返回$data变量

您可以使用一种简单的矫揉造作来代替回声:

$request = "CVentriloStatus->Request() failed. <strong>$stat->m_error</strong><br><br>\n";
您甚至可以使用一个简单的循环来解析数据

foreach($ventriloStatus as $key => $value){
    echo $key.' : '.$value.'<br />';
foreach($key=>value){
回显$key.':'.$value.

您可以使用一种简单的矫揉造作来代替回声:

$request = "CVentriloStatus->Request() failed. <strong>$stat->m_error</strong><br><br>\n";
您甚至可以使用一个简单的循环来解析数据

foreach($ventriloStatus as $key => $value){
    echo $key.' : '.$value.'<br />';
foreach($key=>value){
回显$key.':'.$value.

如果你编写代码,那么最好使用GSto的方法。但是,如果已经编写了大量文本,那么使用Gumbo的方法来节省时间。如果你编写代码,那么最好使用GSto的方法。但是,如果已经编写了大量文本,那么使用Gumbo的方法来节省时间。
ob_start()echo'foobar';$contents=ob_get_clean();
-也这样做,但可读性更强。
ob_start();echo'foobar';$contents=ob_get_clean();
-也这样做,但可读性更强一点。