Reputation: 4713
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?
Upvotes: 10
Views: 22503
Reputation: 839
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.
Upvotes: 1
Reputation: 103617
You might want to enable your error reporting in .htacess
file in public_html folder and try to diagnose the issue depending upon the error message.
Upvotes: 1
Reputation: 11342
Here's a checklist
As a test try saving this as info.php
<?php
phpinfo();
?>
and see if it displays information about your server
Upvotes: 13
Reputation: 34397
If you don't see the html
tags in the source, it means there is a PHP error. Check your view source, and if nothing is shown, check your error logs.
Upvotes: 0
Reputation: 3237
Make sure the file that contains that code is a PHP file - ends in '.php'.
Upvotes: 1