Page 1 of 1
Newbie Having trouble with php
Posted: Thu Jul 10, 2008 3:54 pm
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
'; ?>
Re: Newbie Having trouble with php
Posted: Thu Jul 10, 2008 5:52 pm
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.
Re: Newbie Having trouble with php
Posted: Thu Jul 10, 2008 6:43 pm
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.