Share on Google+Share on Google+

Eval () PHP Function, Example of Eval () PHP Function

Learn how to use Eval () PHP Function to execute PHP code.

PHP eval() Function

In this tutorial we will learn about the PHP eval() function. The php eval() function can be used if you want to store the php command in MySQL table or in text file and then run the same in a PHP script.

The PHP eval() function:

The PHP eval() function evaluates the passed string parameter as PHP code. The string parameter must be a valid PHP code and end with a semicolon, just like regular PHP code.

After the evaluation of the string it returns NULL value if there is no return statement in the string. If there is some parse error in the string the eval() function returns FALSE.

Syntax of eval() function:


Parameter Description
codeasstring The parameter is required and it must be valid PHP code.

Example code of eval() function:

The following example how to use eval() function.

$string = "Hello";
$today = date("F j, Y, g:i a");

$str = 'Say $string to PHP. Today is $today';
echo $str. "<br />";

eval("\$str = \"$str\";");
echo $str;

The out put of the program is:

Say $string to PHP. Today is $today
Say Hello to PHP. Today is August 31, 2010, 4:40 am


Posted on: April 3, 2006 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.


Advertisement null