Newbie Having trouble with php

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
tessray11
Forum Newbie
Posts: 2
Joined: Thu Jul 10, 2008 3:43 pm

Newbie Having trouble with php

Post by tessray11 »

I am having trouble getting PHP to work within a HTML page. If I save the php file as test.php it works.
Code:
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php
echo '<p>Hello World</p>';
?>
</body>
</html>

Result:
Hello World

'; ?>
tessray11
Forum Newbie
Posts: 2
Joined: Thu Jul 10, 2008 3:43 pm

Re: Newbie Having trouble with php

Post by tessray11 »

I was in a hurry previously and did not post all of the relevant information(on a train using wifi heading into a tunnel). So here is all of the information.
When I use the the following php code in a test.php file it works.
Code:
<?php
echo '<p>Hello World</p>';
?>
Result:
Hello World

When i try to put the php code into an HTML file I don't get the same result.
Code:
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php
echo '<p>Hello World</p>';
?>
</body>
</html>

Result:
Hello World

'; ?>

I have tried this in both Firefox an IE and get the same result. Any help would be appreciated.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Newbie Having trouble with php

Post by califdon »

When you say "php file" and "html file", do you mean a text file with either .php or .html extension? Assuming that's what you meant, the answer is that the web server only tries to interpret php code if it recognizes the extension of the file, as specified in its configuration file. By default, web servers only try to interpret files with .php extension. If you have access to the web server configuration file, you can change that, but why would you want to do so? It would mean that the web server would attempt to interpret every file, surely not something you ordinarily want to do.
Post Reply