Alex Rivera | Logout

Echo command doesn't do anything

Asked 2010-06-20T02:59:05.750
10

I've been started studying PHP in my spare time, and the first code example I was given was this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <body>
        <?php
        echo "Hello World";
        ?>
    </body>
</html>

From what I understand, this should write out "Hello World". However, all I see is a blank webpage. Any ideas why this is and how I should go about fixing it?

Edit
Report

1 Answer

1

The code seems fine, certainly it should do what you intend.

Probably what happened is that you named the file with something like example.html, so you have to check the extension. It must look like example.php. With the extension .php at the end of the file you are telling the webserver that this file contains php code in it. That way the <?php echo "Hello World"; ?> is going to be interpreted and do you intend it to do.

answered 2010-06-20T03:25:20.383

Your Answer