Incorporating a bit of PHP code into a web page can turn a boring, static web page into a dynamic, cohesive part of an entire web site. PHP uses simple terms and syntax to tell the web server to insert dynamic data into a web page before it is sent out to the viewer. This brief PHP tutorial shows you just how simple it can be to get started adding PHP to a web page, and also gives you some resources to visit to learn more.
The most basic way to use PHP is to have it create simple text blocks to be displayed on the web page. Every PHP code section on a web page begins with:
<?PHP
and ends with
?>
Between these two statements goes the rest of the PHP code. For this first example we will create a page that simply says "Hello!" to our visitors.
<?PHP
echo "Hello!";
?>
When uploaded to a web server and then opened in a web browser a page with that bit of code will output a blank white page with the word "Hello!" written at the top. Pretty basic, yes, but when we expand the statement to include some other information the information suddenly becomes dynamic:
<?PHP
$todayDate = date("Y/m/d");
echo "Hello! Today is ",$todayDate;
?>
This bit of code asks the computer for today's date and stores it in a variable known as $todayDate. The echo statement then pulls that date in and adds it to the text on the page after the other words, resulting in a page that says:
Hello! Today is 2008/07/06
Additional commands and manipulations can be made to the code to actually make it output things in HTML formatting, allowing a web page to update itself based on whatever information you tell it to gather. The example above is the most simplistic of PHP web pages. The true power and usefullness of PHP comes into play when using PHP together with a MySQL database. At this point such things as content management systems become possible, and any limit to the usefullness and flexibility of a web site goes away. If you are willing to give it a little time and study, learning PHP and incorporating it into your web site can be a very fun and worthwhile venture.
The most basic way to use PHP is to have it create simple text blocks to be displayed on the web page. Every PHP code section on a web page begins with:
<?PHP
and ends with
?>
Between these two statements goes the rest of the PHP code. For this first example we will create a page that simply says "Hello!" to our visitors.
<?PHP
echo "Hello!";
?>
When uploaded to a web server and then opened in a web browser a page with that bit of code will output a blank white page with the word "Hello!" written at the top. Pretty basic, yes, but when we expand the statement to include some other information the information suddenly becomes dynamic:
<?PHP
$todayDate = date("Y/m/d");
echo "Hello! Today is ",$todayDate;
?>
This bit of code asks the computer for today's date and stores it in a variable known as $todayDate. The echo statement then pulls that date in and adds it to the text on the page after the other words, resulting in a page that says:
Hello! Today is 2008/07/06
Additional commands and manipulations can be made to the code to actually make it output things in HTML formatting, allowing a web page to update itself based on whatever information you tell it to gather. The example above is the most simplistic of PHP web pages. The true power and usefullness of PHP comes into play when using PHP together with a MySQL database. At this point such things as content management systems become possible, and any limit to the usefullness and flexibility of a web site goes away. If you are willing to give it a little time and study, learning PHP and incorporating it into your web site can be a very fun and worthwhile venture.















