PHP Eval () function

eval ($string) 
Parameters:This function takes one parameter, as shown in the following above syntax and described below.
  • $string:it must be valid PHP code to evaluate, but must not contain opening and closing PHP tags.
Note.All statements must be properly terminated with a semicolon. For example, initializing the string as "echo" Geeks for Geeks "" will cause a parsing error. To fix, you need to initialize as "echo" Geeks for Geeks ";".Return value:Returns NULL if no return statement is invoked on an input string containing PHP code. Then the value is returned. If a parsing error occurs in the input string, the function returns FALSE.Examples :
Input: $age = 20; $str = "I am $age years old" eval ("$str =" $str ";"); Output: I am 20 years old Input: $str = `echo" Geeks for Geeks ";`; echo eval ($str). ""; Output: Geeks for Geeks 
The programs below illustrate the use of the eval() function:Program 1: $age = 20; $str = `My age is $age` ; echo $str . "" ; eval ( " $str = "$str"; " ); echo $str . "" ; ?> Exit:
My age is $age My age is 20 
Program 2: $str = `echo" Geeks for Geeks ";` ; echo eval ( $str ). "" ; ?> Exit:
Geeks for Geeks 
Link: http: // php. net / manual / en / function.eval.php
Get Solution for free from DataCamp guru