0

I'm just learning PHP, and I tried my first program which is as below

<!DOCTYPE html>
<head> <title>My first PHP</title> </head>
<body>

<?php
echo "<p>Hello world!</p>";
?>

</body>
</html>

But the output I got in my browser was

Hello world!
"; ?>

Why is "; ?> showing up on the browser?

11
  • is this your full code ? and what the extension of file?.html or .php? Commented Oct 5, 2016 at 10:00
  • is your file name with .php? Commented Oct 5, 2016 at 10:00
  • 1
    Are you opening the file through a web-server? Commented Oct 5, 2016 at 10:01
  • 1
    How do you try to open your .php file? c:\path\to\file.php maybe? Commented Oct 5, 2016 at 10:01
  • 4
    Your server is not configured to process php-files. Over. Or you even don't have a web server. Commented Oct 5, 2016 at 10:04

3 Answers 3

1

As u_mulder says in the comments, your webserver (Apache, Nginx, etc) isn't configured to process PHP files. The reason you're getting that output is because your browser is rendering the the below as a single opening HTML tag:

<?php
echo "<p>

and then displaying the subsequent characters:

Hello world!
"; ?>

as text. If you View Source in your browser, you'll see the full contents of your file.

To fix this, you'll need to enable PHP processing in your webserver's configuration - this will be different depending on which server software you are using, but you should be able to easily find a guide.

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

Comments

0
  1. Save your file in with .php extension.
  2. code like this

          <?php 
    
        echo '<p> Hello world! </p> ' ; 
     ?> 
    

their is nothing like that you show.. please check it. Always be sure your php syntax is correct.

2 Comments

I saved it as first.php
If you are learner .. You should read how to run php on your localhost. After this you will get your answer dear .
0

I use Fedora 23, I placed this php file in /var/www/html which is the default root folder of web server.I didn't install php package, so I installed the php package and restarted the server and I got the expected output.

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.