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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: cnewbill at onewest dot net
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Wed May 07 19:01:32 2025 UTC