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. Link to comment https://forums.phpfreaks.com/topic/30261-what-are-the-advantages-of-using-eval/ 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. Link to comment https://forums.phpfreaks.com/topic/30261-what-are-the-advantages-of-using-eval/#findComment-139168 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. Link to comment https://forums.phpfreaks.com/topic/30261-what-are-the-advantages-of-using-eval/#findComment-139211 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. Link to comment https://forums.phpfreaks.com/topic/30261-what-are-the-advantages-of-using-eval/#findComment-139216 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.