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

Eval () PHP Function

By , About.com Guide

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
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

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

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

All rights reserved.