ob_get_clean在php中返回空

时间:2014-10-16 13:40:10

标签: php parsing buffer output

我有大量数据作为字符串,包括文本和大量图像。

该字符串包含特殊标签,如下所示,以及普通文本+图像。

{{ title }}

我有一个函数检查该字符串是否包含任何php标记?&gt;或<?php

功能是

    protected function parseTxt($text){
        echo $text; //Gives me correct string
        ob_start();
        $result = eval('?>'.$text.'<?php ');                        
        if ($result === false){
          echo '<br />You have a syntax error.The snippet of text that contains 
the error has been output below:<br />';
          exit(str_replace(array('?>', '<?php '), '', $text));
        }
        return ob_get_clean();
      }

我把str作为null。

我有PHP 5.5,我的内存限制增加到512

请建议我没有任何其他线索。非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

您的代码必须在到达ob_get_clean()之前退出。 另外,不要使用eval。不,不。为什么不只是echo $text

P.S。

eval是邪恶的