12.2. Embedding PHP Into HTML

There are several ways to embed PHP code into HTML documents. One way is to put the PHP code within the tags <? ... ?>:

<? echo "hello, world!"; ?> 

Most PHP programmers choose this syntax. If PHP is combined with XML, however, there are conflicts with this syntax. In XML the <? ... ?> construct is a special thing called a processing instruction. If PHP and XML are needed in the same file, one can use the alternative PHP tag <?php ... ?>:

<?php echo "hello, world!"; ?> 

Some HTML editors (such as FrontPage) don’t like processing instructions, so another alternative is to use the <SCRIPT> tag. This is the syntax:

<SCRIPT LANGUAGE="php"> echo "hello, world!"; </SCRIPT> 

And last but not least, the final way is ...

Get Open Source Web Development with LAMP: Using Linux, Apache, MySQL, Perl, and PHP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.