1. Computing & Technology

Discuss in my forum

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 ()

©2012 About.com. All rights reserved.

A part of The New York Times Company.