The last approach I want to discuss involves using the include and require functions. As you may recall , these functions include a file in the PHP code. The file is considered to be a PHP file, regardless of the extension on the name. If PHP code appears in the included file, it is surrounded in <? and ?> tags. You may want to turn back to the functional reference to refresh yourself on the differences between include and require , but they aren't particularly important to this discussion.
Certain chunks of HTML must appear on every well-formed page. Additionally you may develop repeating elements such as a company logo. Rather than write them into every page, you may choose to put them into a file and dynamically include them. It contains HTML you might include at the top of every page on a site. The opening and closing code to form a complete page.
Start of HTMLPage<HTML>
End of HTML Page</BODY>
Page ContentThis is the body of the page.<BR>
In this way, HTML and PHP are separated into modules. In this example I have hardcoded the inclusion of a two-line HTML file, but I could just as easily have included the color tables. The HTML can be reused from page to page, and if I need to add something to every page on the site, I need to edit only that one file. I might want to add the PHP function. It will then be available for use inside the code.
It may occur to you that this approach is exhibiting another pattern. Every page on the site will simply become three calls to require. The first and last calls will always be the same. In fact every page on the site will vary simply by the name of the file included in the second require statement. This takes us beyond the issue of integrating HTML and PHP and into the structural design of a site. It is possible to create a site that has exactly one PHP script.
PHP Related Interview Questions
|PHP Interview Questions||MySQL Interview Questions|
|PHP+MySQL Interview Questions||Drupal Interview Questions|
|MYSQL DBA Interview Questions||PHP5 Interview Questions|
|WordPress Interview Questions||Joomla Interview Questions|
|CakePHP Interview Questions||CodeIgniter Interview Questions|
|PHP7 Interview Questions|
An Introduction To Php
Variables, Operators, And Expressions
Classes And Objects
I/o And Disk Access
Time, Date, And Configuration Functions
Parsing And String Evaluation
Sorting Searching And Random Numbers
Integration With Html
Efficiency And Debugging
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.