How to use eval function in php?
The eval function in PHP is an inbuilt function that evaluates a string as PHP code.
1. Code:
<?php $age = 20; $str = 'My Soltuts $age years old'; echo $str. "<br>"; eval("\$str = \"$str\";"); echo $str. "<br>"; ?>
2. Example:
Input:
Input : $age = 20; $str = "My Soltuts $age years old" eval("\$str = \"$str\";");
Output:
Output : My Soltuts 20 years old
3. Syntax:
Syntax: eval( $string ) Parameters: This function accepts a single parameter as shown in above syntax and described below. $string: It must consist of a valid PHP code to be evaluated but should not contain opening and closing PHP tags.