How to use eval in PHP

In this article I will explain how eval function can be used in PHP.
  • 1681

eval() Function

This function evaluates a string as PHP code.

Syntax

eval(phpcode)

 

Parameter  Description
phpcode  Required. Specifies the PHP code to be evaluated

Example

<html>
<body>
<?php
$string = "beautiful";
$time = "winter";

$str = 'This is a $string $time morning!';
echo $str. "<br />";

eval("\$str = \"$str\";");
echo $str;
?>
</body>
</html>

 

Output


eval-php.jpg

You may also want to read these related articles Click here

Ask Your Question 

Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.