azemda
azemda

Reputation: 79

PHP echo output

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?

Upvotes: 0

Views: 138

Answers (3)

azemda
azemda

Reputation: 79

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.

Upvotes: 0

iainn
iainn

Reputation: 17417

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.

Upvotes: 1

Kumar Rakesh
Kumar Rakesh

Reputation: 2708

  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.

Upvotes: 0

Related Questions