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?

2
  • How are you opening the file in Chrome or IE? Commented May 28, 2014 at 21:11
  • 2
    you need to be running a websever Commented May 28, 2014 at 21:11

3 Answers 3

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.

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

3 Comments

i am using WAMP, do u suggest that i need to open the php file with it ?
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 stackoverflow.com/questions/6233572/…
ahh ok ok , it worked now, i had to change the extension of my file to .php , .html didn't work at all @nullability
1

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

Look at XAMPP

Comments

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.

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.