Echo command doesn't do anything
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 开发者_如何学GoTransitional//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?
Here's a checklist
- What server are you running? Does it support php?
- Is PHP enabled?
- Is your file named with the extension .php?
- When you use View Source can you see the code in the php tags? If so PHP is not enabled
As a test try saving this as info.php
<?php
phpinfo();
?>
and see if it displays information about your server
Make sure the file that contains that code is a PHP file - ends in '.php'.
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.
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.
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.
精彩评论