Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Hello, World" PHP page is not working

Tags:

php

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?

like image 926
Franz Payer Avatar asked Apr 09 '11 22:04

Franz Payer


People also ask

How do you write Hello World in PHP?

$string = 'Hello World! <br>'; // You can echo the variable, similar to the way you would echo a string. echo $string; // You could also use print. print $string; // Or, if you are familiar with C, printf can be used too.

How do I start PHP in HTML?

Step 1: Firstly, we have to type the Html code in any text editor or open the existing Html file in the text editor in which we want to use the PHP. Step 2: Now, we have to place the cursor in any tag of the <body> tag where we want to add the code of PHP. And, then we have to type the start and end tag of PHP.


1 Answers

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.

like image 148
JLZenor Avatar answered Oct 31 '22 08:10

JLZenor