Creating a dynamic HTML page by using PHP is not as complex task as it might appear to some persons. As PHP programming language is comparatively flexible programming language, you add dynamism in your website by integrating it. Though you do not have to be a pro for executing this task, you need to remain aware of the ins and outs of web programming for this purpose. A good knowledge of HTML structure and conditions can help you a lot in this task. Lets start from the beginning:
Embedding PHP in HTML
PHP can be integrated with an existing HTML document easily. If you want to display a simple message for example: “This is my first PHP Code”, you just have to use this simple code:
<HTML>
<BODY>
<?php
echo ‘ This is my first PHP Code’;
?>
</BODY>
</HTML>
The phrase “This is my first PHP Code” will automatically conform to the existing style of the HTML document. Use of PHP will enable the document to interpret the code in different way. However, there are some issues that you should not ignore at any cost. PHP code should be used within<?php and ?gt;; and the keyword echo should also be used for generating plain text. Before proceeding further, readers should remain aware of these above-mentioned issues.
Splitting PHP Blocks
Now, assume the fact that we have two variables $motd and $motd_severity. $motd contains the current system named “message of the day” and the next one contains the value of the current MOTD:
- Information
- Medium
- High
Depending on the severity, the presentation of the MOTD will be changed or modified. Choose blue text for information, green text for medium and red text for high. If you wish, you can add a little icon or any other HTML elements for this purpose.
This task can be performed in two different ways. You can either insert a piece of PHP in HTML document by breaking out PHP code block separately or a piece of PHP should be created to echo HTML element into the text stream. By writing this code, you would be able to actualize the first option:
<HTML>
<BODY>
<?php
if ($motd_severity == ‘High’) {
?>
<FONT COLOR=Red>
<?php
} elseif ($motd_severity == ‘Medium’) {
?>
<FONT COLOR=Green>
<?php
} else {
<FONT COLOR=Black>
}
// end of if block
?>
<?php echo $motd; ?>
</FONT>
</BODY>
</HTML>
As the formatting is not complicated, standard inline PHP syntax can be used for generating better result. If you want to add style, icons etc in the HTML document, you will find it easier to use HTML blocks in PHP as opposed to PHP blocks in HTML. In the next stage, we can integrate all the HTML tags within a PHP code. For this purpose, you have to create a .php file that will contain ?> at the end and <?php at the beginning. Within these tags, you have to use only php code for generating desired output:
<?php
echo ‘<HTML>’;
echo ‘<BODY>’;
echo ‘Hello from PHP!’;
echo ‘</BODY>’;
echo ‘</HTML>’;
?>
If you can manage to maintain these above-mentioned tips carefully, you will be able to utilize the flexible nature of PHP skillfully. If you still consider this as a difficult task, you can opt for the assistance of professional web development company, which is offering PHP programming and PHP database programming services at an affordable rate.










May 19th, 2009 at 8:40 am
nice little tutorial this - its important to understand the different ways in which you can output html from php. The main 2 in my opinion are: you can either do it the hard way:
echo “This is the hard way”;
or the easy way:
echo ” ?>
The easy way
Easy way is best to get the predictive html features from dreamweaver and the like
June 2nd, 2009 at 4:49 am
Nice basic tutorial. PHP is not that hard to learn if you have some basic programming skills.
It is a very common language also. So if you learn to program in PHP your skilss will be usefull for a long time.