Page 1 of 1

File named .php but content is HTML still works ??!!

Posted: Fri Mar 14, 2014 9:52 pm
by mingZhao
Hello everyone, I'm new to web development and I found something weird to me:

a file named ajax.php has content as following still works

Code: Select all

<html>
<body>

Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>

</body>
</html>
Doesn't it have to be <?php ?> ??

Re: File named .php but content is HTML still works ??!!

Posted: Fri Mar 14, 2014 10:38 pm
by requinix
PHP doesn't care about what's outside of the <?php ?> tags: it'll get outputted just like if you had used echo on it all.

Code: Select all

<?php

echo "<html>
<body>

Welcome ";

echo $_POST["name"];

echo "<br>
Your email address is: ";

echo $_POST["email"];

echo "

</body>
</html>";

?>