HTML to PHP Converter for integrating templates
We can integrate HTML code inside PHP script to display the pages in web browser after proper formatting. After all our browser does not understand PHP and it can only understand HTML tags. So to Keep HTML tags inside PHP script we need to make it compatible to PHP. This is very much required when we have to include PHP script and HTML both in same page.
There are two ways to do this. One way is to echo or print the html tags inside the PHP code and the
second way is to close the PHP script execution area and return to HTML mode to display HTML tags.
Displaying HTML tags outside PHP script tags
Without keeping both together we can keep both in different areas so PHP engine does not come across HTML tags. However this is not practicable and is not a good idea for developing complex applications. Here is a sample code for this.
// PHP script area
<br> this is " our HTML area " we can use any tags or chars as we like "
Displaying HTML tags inside PHP script
By printing the same HTML code from inside the PHP code we can get same result and comparable less load or delay in file execution.
But in this case we have to take care some points as double quotes inside echo
Command of a PHP script is not allowed. The code below will generate error as we have kept double quotes inside the PHP script area
echo "<table width="100%" border='0' cellspacing='1'
cellpadding='0'>"; // Double quotes inside this line not allowed.
There are two ways to solve this . One is to use single quotes in place of double quotes or to use PHP escape command ( \ ) to tell PHP not to consider the
character next to it while evaluating. Here is the correct code using escape
echo "<table width=\"100%\"border='0'
This way any number of HTML tags can be converted to PHP code
Be the first to post comment on this article :