Franz Payer
Franz Payer

Reputation: 4137

"Hello, World" PHP page is not working

I am trying to start programming in PHP. I found this example "Hello, World" PHP page.

Here is the code:

<html>
    <head>
        <title>PHP Test</title>
    </head>

    <body>
        <?php echo '<p>Hello World</p>'; ?>
    </body>
</html>

However, instead of displaying:

Hello World

It displays:

Hello World
'; ?>

Viewing the source shows

<html>
    <head>
        <title>PHP Test</title>
    </head>

    <body>
        <?php echo '<p>Hello World</p>'; ?>
    </body>
</html>

instead of

<html>
    <head>
        <title>PHP Test</title>
    </head>

    <body>
        <p>Hello World</p>
    </body>
</html>

So it looks like it did not get parsed by Chrome. What is causing this problem?

Upvotes: 7

Views: 20525

Answers (5)

Hassan Saeed
Hassan Saeed

Reputation: 7100

for this purpose you should put your code into php file make helloworld.php file
and put in wamp www folder and run with wamp server.
for hello world program in php just follow this tutorial
but before that you should have wamp server or xamp server on your pc
(wamp/xmap are open source software's and easily can found on google)
your 1st php program code:-

<?php
echo "hello world";
?>

output:- hello world Helping Step by Step Tutorial :https://www.youtube.com/watch?v=7qtqzhdEX-c
after this tutorial you can able to move other intermediate level programs of php.

Upvotes: 0

Iain
Iain

Reputation: 11

I had the same problem until somebody helped me out. Do this:

Access the file from your browser like so: http:// (localhost) /hello.php and it will come up fine provided your WAMP, XAMPP, etc. is running online and shows green. Remove spaces and parentheses around localhost). Also the file must be in the www directory of your Wamp, etc. folder in the root directory.

Upvotes: 0

JLZenor
JLZenor

Reputation: 1480

Make sure the file is named .php and not .html or .htm. Also make sure you have uploaded it to a PHP web server.

Chrome (or any browser) does not parse PHP at all... the server parses the PHP and passes the HTML to the browser. Bottom line, the browser should never know PHP exists.

Upvotes: 15

Kev
Kev

Reputation: 119816

Looks like PHP isn't installed on your web server or you just opened the page directly off of your file system.

Upvotes: 2

Rob Williams
Rob Williams

Reputation: 1470

Make sure you've used the same type of quotes - " and ' are completely different beasts.

Upvotes: -2

Related Questions