1

I create a new HTML file for my project using Dreamweaver and i added a simple php code:

<!DOCTYPE html>
<html>
<body>

<?php
echo "My first PHP script!";
?>

</body>
</html>

so far nothing is appearing while i open the file with google chrome and IE, any thoughts?

Zame
  • 320
  • 1
  • 7
  • 17

3 Answers3

4

PHP has to be executed on the server. Upload it to a web server that supports PHP, or install your own web server locally such as WAMP. You then need to access the file with a URL rather than just opening it. A local URL will look like http://localhost/ or http://127.0.0.1/.

Your file also needs to have the extension .php if it contains PHP code. If you really want to use PHP inside a .html file, your web server will need to be set up specially to handle this.

nullability
  • 9,851
  • 3
  • 41
  • 59
  • i am using WAMP, do u suggest that i need to open the php file with it ? – Zame May 28 '14 at 21:13
  • Your PHP file needs to be in WAMP's web root folder, then you can view the page using your web browser by accessing the appropriate URL. See http://stackoverflow.com/questions/6233572/where-is-the-web-server-root-directory-in-wamp – nullability May 28 '14 at 21:16
  • ahh ok ok , it worked now, i had to change the extension of my file to .php , .html didn't work at all @nullability – Zame May 28 '14 at 21:18
1

PHP requires a webserver and an interpreter. Browsers cannot handle PHP on its own.

Look at XAMPP

JRL
  • 831
  • 6
  • 17
0

A good idea to check if your php file is working properly is to load phpinfo function. This function will show details about your PHP installation:

<?php
   phpinfo();
?>

If what you see on the screen is this php code with the entire opening and closing tags (), then you are not running the page with PHP.

Fabiano
  • 4,503
  • 2
  • 25
  • 29