Hi all
I wrote a small code to display HTML code from file as follow:

$html= file_get_contents("templateHTML.php");
echo $html;

file templateHTML.php as follow follwing :
[INDENT]<html>

<head>
<title>Login Form</title>
</head>

<body>

<?php
echo "Login Form!";
?>

</body>
</html>[/INDENT]

But I did not execute PHP echo command. if I did not insert PHP command inside just normal html, it is OK.
So, my question is how to execute php commands in my templatePHP.php file

Thanks
Matt

    Not sure if I follow you, but I think instead of using file_get_contents() you could just use an include() statement instead and get what you want. Give that a try and see if you get the results you want...

      Hi jkurrle

      get_file_contents is only example to know that $html variable stores a string and in the string contains php code. Because the $html variable may store content from database, etc.

      Thanks

        If you're loading a file and you want PHP to parse it for PHP code, use [man]include[/man] or [man]require[/man] as jkurrle suggests.

        Otherwise, you would have to [man]eval/man the string. Be careful, though; depending upon where the information comes from, you don't want malicious users to be executing arbitrary PHP code on your server.

          Perhaps, but looking at your code, it shouldn't work. Because the "echo $html " sends the raw data to the screen, it does not interpret it. PHP passes through the code only once. That's why I suggested you use an include() statement instead...

            Write a Reply...