在PHP CodeIgniter中获取回显字符串的值?

在PHP CodeIgniter中获取回显字符串的值?,php,codeigniter,echo,Php,Codeigniter,Echo,我需要在CodeIgniter或PHP中获取echo-ed字符串的值 比如说 class SampleClass { function myFunc() { echo "true"; } } class TestSampleClass { $obj = new SampleClass(); function test_myFunc() { $obj->myFunc(); // I want to get the 'true' string to be comp

我需要在CodeIgniter或PHP中获取echo-ed字符串的值

比如说

class SampleClass {

 function myFunc() {
  echo "true"; 
 }

}

class TestSampleClass {

 $obj = new SampleClass();
 function test_myFunc() {
  $obj->myFunc();
  // I want to get the 'true' string to be compared..
  // how can i get the string 'true' that is echoed in myFunc()
 }

}
可能吗

请帮忙


非常感谢。

虽然我认为这个问题与CodeIgniter无关,但您可以通过捕获缓冲区并将其发送到某个回调函数来明确检查输出

<?php
class SampleClass {

 function myFunc() 
 {
    echo 'true'; 
 }

}

class TestSampleClass {

 static function compare($buffer)
 {
    if ($buffer == 'true')
    {
       return 'Yes, it was true';
    }
    else
    {
       return 'Sorry, it was not true';
    }
 }

 function test_myFunc() 
 {
    $obj = new SampleClass();

    ob_start('TestSampleClass::compare');

    $obj->myFunc();

    ob_end_flush();
 }

}

$TSC = new TestSampleClass;

echo $TSC->test_myFunc();
?>


您可以看到输出:

为什么不返回一个值?在CodeIgniter中,您应该只输出/回显视图中的内容。