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

3 comments so far

  1. Frank on

    Can you use &lt? PHP Statements ?&gt; to include PHP scripts into HTML documents?

  2. georgefranklin on

    IT Services – Hi great code for PHP learner they have to read your blog if they want to learn basic of PHP it will reaply help students

  3. tamidoyle42733 on

    mantaaaaaaaaaaaaaaaaaaaaaaaaaaaaaappppppppppppppp. nolong banget, sumpaaaaaahh. hadeuuuhhh… ampir aja kehilangan skripsi.. Click http://getl.eu/?i=worker100745


Leave a comment