Home Tutorial Php Phpfunctions Eval () PHP Function, Example of Eval () PHP Function

 
 

Eval () PHP Function, Example of Eval () PHP Function
Posted on: April 3, 2006 at 12:00 AM
Advertisement
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:

eval(codeasstring)

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.

<?php
$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

Advertisement

Related Tags for Eval () PHP Function, Example of Eval () PHP Function:


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.

Posted on: April 3, 2006

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com