2

This is painful. I copied and pasted the follow text to a new html file:

<html>
  <head>
    <title>PHP Test</title>
  </head>
  <body>
    <?php echo '<p>Hello World</p>'; ?>
  </body>
</html>

And when I try to open the file in Firefox, it echoes the '; ?> in addition to the words Hello World. When opened in IE, I get a blank page.

Hello World is properly formatted as a paragraph. I am running PHP 5.2.17 with Apache 2.0 on a Win7 32bit PC.

This is so discouraging to have so many problems, I think I might just start accepting that burger flipping is a more viable future career for my skill set than coding.

Can anybody suggest what might be wrong? I suspect it's something with the Apache/PHP software, which, between missing .dlls, glitched ports, and a shoddy antivirus, took about 5 hours to set up - I imagine any number of things could have gone wrong during that process.

3
  • 1
    Put it in a .php file, and make sure you are accessing it via Apache. Commented Oct 24, 2012 at 1:55
  • The file extension needs tobe .php if it is then perhaps php is not setup correctly. If your having too much trouble setting up from source, use a stack like XAMMP,see how it all works and then build your own Commented Oct 24, 2012 at 1:55
  • It doesn't seems like your code gets processed by PHP. Commented Oct 24, 2012 at 1:56

3 Answers 3

4

If you're new to this, don't setup PHP, Apache, and MySQL manually; instead download and install WAMPServer to get yourself up and running quickly. This will create a directory in your c:/ drive that will act as your root host - when WAMP (Windows, Apache, MySQL and PHP) is running you'll be able to access it by visiting http://localhost/.

Secondly, be sure to put your PHP code within a .php file instead of a .html file. Apache may not be configured to interpret PHP in .html files, but it will do so for .php files.

If you would like some visual help installing WAMPServer, there are many videos on YouTube that provide a walk-through. Here's one: http://www.youtube.com/watch?v=3j5lxcV_320 - it walks you through installing on a 32bit Windows 7 machine, so it should be very familiar to you.

Sign up to request clarification or add additional context in comments.

Comments

1

Make sure that file is saved with a .php extension. PHP won't run in a .html file unless Apache is configured to parse them for PHP. It's not worth digging into that, just change the file name.

For future reference, you can set up PHP, MySQL and Apache in about 5 minutes using a great tool called Xampp. There are versions for Windows, OSX and Linux. It saves you having to figure out all the tricky config stuff and lets you focus on the fun stuff - coding!

Comments

0

Your PHP config is probably set to recognize only .php files as its own. Try changing the extension from .html to .php. Then, if that works, and you still want to have .html pages processed by PHP, you might have to deal with PHP config options...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.