> Ideally, i'd like to evaluate the code the user has submitted, and if an
> error is generated, notify the user of that fact.
> Eval always returns false, and I'd like no runtime error to be generated.
> Perhaps an error-handler is what's needed?
> What can you suggest?

I think this should illustrate how to do that:

    $code = '

$a = 1;
print $a;


    $output = ob_get_contents();
    if($php_errormsg) echo "Error was: $php_errormsg<br>\n";
    else echo "Output was: $output<br>\n";

A couple of tricks:

1. Turning off PHP's error_reporting makes sure no errors are shown by PHP
2. Turning on track_errors puts any errors into the $php_errormsg variable
3. Turning on output buffering lets you catch the output from the code you
   are testing
4. Preceding the eval()'ed code with ?> makes sure you start the code off
   in normal HTML mode since eval() actually assumes what you feed it
   starts in PHP mode which is likely not the case for you.


PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to