1. Home
  2. Computing & Technology
  3. PHP / MySQL

Eval () PHP Function

By Angela Bradley, About.com

Definition: Eval () is used to evaluate the input string as PHP. It is like using the Echo () function in the sense that it outputs everything, except instead of outputting it as text, it outputs it as PHP code to be executed. One use of this is to store code in a database to execute later.
Also Known As: Evaluate String
Examples:
<?php
$name = 'Joe';
$name2 = 'Jim';
$a = 'My friends are $name and $name2';
print $a . "<br>";
eval("\$a = \"$a\";");
print $a . "<br>";
?>
This would output My friends are $name and $name2 when first called with the print statement, but would output My friends are Joe and Jim when called the second time after running eval ()

Explore PHP / MySQL

More from About.com

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. PHP Functions
  5. Eval PHP - Eval Function - Evaluate Code PHP

©2008 About.com, a part of The New York Times Company.

All rights reserved.