At 13:28 27.02.2003, Dennis Heuer spoke out and said:
--------------------[snip]--------------------
>One single question. Is including() a script on runtime only possible with 
>files or can I include() code from a database?
--------------------[snip]-------------------- 

If you have code in your database, you don't include() it but eval() it.
Make sure though that the code is error-free (at least no fatal errors):

    global $php_errormsg;
    $php_errormsg = null;
    $result = @eval($code);
    $error = $php_errmsg;

This will execute the contents of "$code" as if it were a PHP source file.
You can even use such constructs:

    // do some stuff here
    ?>Hello from outside PHP<br />
    <?php
    // do some more stuff here

If your code uses "return" to return a value, eval will have this as its
return value (see sample above). If your code doesn't use return, $result
will be null.

If youc code produces a fatal error, @eval will terminate the script (not
only the eval!) without any further message. Omitting the "@" (using
$result = eval($code)) will print the error, notification, or warning to
stdout, as usual. Additionally (in both cases), $php_errormsg will contain
the very last PHP error (thus I read it out immediately).

Works like a charm, half of my apps depend on that...


-- 
   >O Ernest E. Vogelsinger 
   (\) ICQ #13394035 
    ^ http://www.vogelsinger.at/


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

Reply via email to