php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #8282 Is there a function for this?
Submitted: 2000-12-15 14:50 UTC Modified: 2002-04-27 14:13 UTC
From: cnewbill at onewest dot net Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.0.3pl1 OS: Linux
Private report: No CVE-ID: None
 [2000-12-15 14:50 UTC] cnewbill at onewest dot net
I guess this is more of a hack than anything, but I really needed eval()'s code NOT to be displayed right away. So I used ob_start(), ob_get_contents(), and ob_end_clean(). 

<?php 

$stuff = "Hello, "; 

ob_start(); // start buffer 
eval("print 'World!';"); // execute code 
$retval = ob_get_contents(); // return executed code 
ob_end_clean(); // delete the buffer 

print $stuff.$retval; 

?> 

This would print "Hello, World!" instead of "World!Hello, ".

Is there a function to do this already?

Thanks,
Chris

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-01-10 02:01 UTC] david@php.net
so why don't you have your own

function quiet_eval($code)
{
  ob_start();
  eval($code);
  $retval = ob_get_contents();
  ob_end_clean();
  return $retval;
}

as I understand it, zend output buffers can be nested, so no issues with it interfering with existing buffers.
 [2002-04-27 14:13 UTC] jimw@php.net
this is, indeed, exactly the sort of thing that output buffering is for.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 13:01:29 2024 UTC