SQL PHP HTML ASP JavaScript articles and free scripts to download
 

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
// 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
<?Php
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 command.
 <?Php
echo "<table width=\"100%\"border='0' 
cellspacing='1' cellpadding='0'>";  
?>

This way any number of HTML tags can be converted to PHP code



Further readings
Introduction to PHP: How scripting languages work
PHP beginners guide
echo command & escape character for string outputs
Adding delay to the script execution time by using sleep function
Disabling a part of the code by using comments in PHP
Printing Numbers 1 to 50 to screen
PHP Info: Details on PHP script settings & installation at server end
php_uname: Server OS details
PHP.ini file: PHP server configuration setting file for Edit or update
ini_get: PHP function to get configuration settings from php.ini file
ini_set: PHP function to change the configuration settings of php.ini file
PHP Version : What is the version of PHP running at the server
Installing PHP on windows server and IIS
Installing PHP5 on windows server and IIS
Setting up PHP in Windows Vista OS to run in IIS7 web server
Configuration of IIS7 to run PHP scripts with ISAPI module
Extension directory of PHP to store dll files for windows
Error messages Display off or On by using display_errors function in php.ini file
Using HTML inside PHP script, displaying tags

Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked

Join Our Email List
Email:  
For Email Newsletters you can trust
Basics
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2013 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer