11Tami Posted December 11, 2006 Share Posted December 11, 2006 Hello, would like to know what eval() is good for doing in php? Please don't refer me to the manual, already been there. Need a description in simple terms. Thanks a lot. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted December 11, 2006 Share Posted December 11, 2006 it will evaluate a string as a string, and it will not as an executable string. variables will not be used as variables.[code]<?php$string = 'cup';$name = 'coffee';$str = 'This is a $string with my $name in it.';echo $str. "\n";eval("\$str = \"$str\";");echo $str. "\n";?> [/code]Output:This is a $string with my $name in it.This is a cup with my coffee in it. Quote Link to comment Share on other sites More sharing options...
11Tami Posted December 11, 2006 Author Share Posted December 11, 2006 Thanks but can you make it more simple for someone who doesn't do scripting all the time? I have no clue what you just said. I know there are many types of strings. I don't see a difference between a string and an executable string. I believe these are variables $ but everything I saw said eval can use variables. So I don't understand your description. Please explain the difference someone and explain it like your are talking to someone in high school who hasn't done much scripting? Thank you very much. Quote Link to comment Share on other sites More sharing options...
utexas_pjm Posted December 11, 2006 Share Posted December 11, 2006 eval lets you treat a string like it's valid PHP. For example:[code]$sum = 1 + 1;echo $sum;// would print: 2[/code]likewise..[code] eval('$sum = 1 + 1;'); echo $sum; // would print 2[/code]If you'd like to see some less trivial uses let me know. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.