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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mingZhao
Forum Newbie
Posts: 1
Joined: Fri Mar 14, 2014 9:47 pm

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

Post 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 ?> ??
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

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

Post 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>";

?>
Post Reply