eval() Function in PHP | Evaluate PHP String

Date Published: 27/08/2022 Published By: JaiSchool

This function expects PHP code as a string in its parameter and evaluates it.

It is helpful when you have stored some PHP code in the database, to run that code as PHP code you need the eval() function.

eval() function Syntax




$php_code_string = 'echo "jaischool<br>";echo $_SERVER["REQUEST_URI"];';



Make sure the code as a string does not have any opening and closing PHP tags.

Evaluate PHP code From mixed Html and Php string


$phphtml_code_string = '<!DOCTYPE html>
		$title = "I am title";
		$body = "This code will go in body";
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title><?php echo $title; ?></title>

<?php echo $body; ?>


eval(' ?>'.$phphtml_code_string.'<?php ');


Publish A Comment

Leave a Reply

Your email address will not be published. Required fields are marked *