..
The eval function is used to run the PHP code that may be present in a string variable.
The use of eval proves quite useful when, for example, you need to store pieces of code within a database and then run them on output.
Here's an example comparing to eval echo:
<? Php
/ / Create a simple variable string
$ Site = "centre-equestre-lepuy.com";
/ / Create a second variable that needs the first
$ Sentence = '$'re visiting the site';
/ / I try to print the second sentence with echo
echo $ sentence.
"<br />";
/ / Now try to parse sentences with eval $ ...
/ / I must remember to use the quotes!
eval ("\ $ sentence = \" $ sentence \ ";");
/ / Mold again to see the effect of eval
echo $ sentence;
?>
Following the result of our code:
$'re Visiting site You're visiting centre-equestre-lepuy.comAs you can see the second line (the work of eval) is very different from the first ...
| |
Linux (Course)
Complete guide to open-source system. From 49 €. |
| |
MySQL (Course)
Management of open-source database. From 39 €. |
| |
PHP (Course)
Full course for creating dynamic Web sites. From 49 €. |