Mixing PHP statements in HTML documents

One nice thing about PHP pages is that you can easily mix PHP statements in HTML documents with XML processing tags like this: <?php PHP Statements ?> Here is a good example of mixing PHP statements with normail HTML document text:

<?php /* HeadOrTail.php 
* Copyright (c) 2002 by Dr. Herong Yang, http://www.herongyang.com/ 
*/ ?> 
I am tossing a coin now. Guess what the result will be? 
<?php $coin = rand(0,1); ?> 
<?php if ($coin==1) { ?> 
   Head 
<?php } else { ?> 
   Tail 
<?php } ?>

Run this script and see what you will get?

The above example is taken from PHP Tutorials – Herong’s Tutorial Notes – PHP Syntax

My First PHP Script – Hello.php

Use any text editor, and enter the first PHP script, Hello.php:

Hello <?php echo "world!"; ?>

Run this file at the command line or on Web server, you will get:

Hello world!

If need to help on downloading and installing PHP on your local system, read this simple tutorial guide: Introduction and Installation of PHP.

Having trouble to run your first PHP script? Leave a message in the comment area.

PHP Tutorials – Herong’s Tutorial Notes

This 129-page long free tutorial book is an excellent starting point to learn PHP with tutorial exercises:

PHP Tutorials – Herong’s Tutorial Notes

Topics include array, CGI, CLI, cookie, database, directory, download, file, GB2312, header lines, HTTP, IIS, image, language, localization, mail, MySQL, non ASCII, output buffer, PHP, redirect, request, session, SMTP, SOAP, SOAP Extension, SQL, Unicode, WSDL.

Hope you like it.

What Is PHP?

PHP stands for PHP: Hypertext Preprocessor, a recursive acronym. It is mainly a Web server side scripting language. But it can also be used for other purposes.

PHP was originally created by Rasmus Lerdorf in 1995 as a simple Web page generation tool named as PHP/FI (Personal Home Page/Forms Interpreter). Today it becomes the number one of server side scripting languages. Here is a comparison of number of matches on Google for key words: “PHP script”, “Perl script”, and “ASP script”:

Key words     Number of matches
PHP script    13,600,000
Perl script   11,900,000
ASP script     8,650,000

What do you think?

Welcome to PHP101.WordPress.com

PHP101.WordPress.com, a place to share PHP Developer tutorial notes. Comments are welcome.

Follow

Get every new post delivered to your Inbox.