PHP Code:
<?php?>
or the shorthand PHP tag that requires shorthand support to be enabledon your server...
<??>
If you are writing PHP scripts and plan on distributing them, we suggest that you use thestandard form (which includes the ?php) rather than the shorthand form. This will ensurethat your scripts will work, even when running on other servers with different settings.
How to Save Your PHP Pages
If you have PHP inserted into your HTML and want the web browser to interpret itcorrectly, then you must save the file with a
.php
extension, instead of the standard
.html
extension. So be sure to check that you are saving your files correctly. Instead of
index.html
, it should be
index.php
if there is PHP code in the file.
Example Simple HTML & PHP Page
Below is an example of one of the easiest PHP and HTML page that you can create andstill follow web standards.
PHP and HTML Code:
<html><head><title>My First PHP Page</title></head><body><?phpecho "Hello World!";?></body></html>
Display:
Hello World!If you save this file (e.g. helloworld.php) and place it on PHP enabled server and load itup in your web browser, then you should see "Hello World!" displayed. If not, pleasecheck that you followed our example correctly.We used the PHP command
echo
to write "Hello World!" and we will be talking ingreater depth about how echo is special later on in this tutorial.