Complete newb question (.php vs .html file)

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
djarv
Forum Newbie
Posts: 1
Joined: Mon Sep 20, 2010 5:24 pm

Complete newb question (.php vs .html file)

Post by djarv »

I'm having a few problems understanding how PHP is integrated with HTML (and/or vice versa); the problem seems to be too much information on the web sometimes.

Anyway, I found this small snipped of code where it was implied that it would run as a .php or .html file but that seems not to be the case. The .php file works fine (outputs five lines of 'Menu Item N'); the .html outputs only one line ('Menu Item').

So my question is: why doesn't the html version work?

<html>
<head></head>
<body>
<ul>
<?php for($i=1;$i<=5;$i++){ ?>
<li>Menu Item
<?php echo $i; ?>
</li>
<?php } ?>
</ul>
</body>
</html>


Thanks for bearing with my newbieness.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Complete newb question (.php vs .html file)

Post by requinix »

PHP won't execute the file unless you give it a .php extension. There are ways around this but for now just use the right file extension.
Post Reply