The first and most obvious approach to using PHP is to build HTML files as you have always done, inserting PHP tags as if they were HTML tags. This could take the form of repeating HTML that you replace with a call to a PHP function. It could take the form of a large block of PHP code that generates database output. Or it could be a script that processes a form submission. These are all situations where the impact of PHP on the site is slight. This is a good first step for those new to programming. You are able to insert thesmallest amount of PHP code as a test. As your experience and confidence grow, so willyour reliance on PHP.
Let's examine creating a PHP function to replace repeating HTML. One great aspect of cascading style sheets is that they allow you to redefine how tags behave. Unfortunately, this technology is available only in the newest versions of Navigator and Internet Explorer. You can provide similar functionality on the server side with PHP. Suppose we would like all of our headers to be in uppercase letters, bold, size 7, and blue. The solution is to write a function that takes a string and prints it in the proper format.
I've created a function called PrintTitle. This function wraps a given string in HTML tags. In some ways the code is more readable than if I had simply written it as static HTML, because each time there is a title, we see the call to the PrintTitle function. This may have more meaning than the collection of tags for which it stands. This is one of the benefits of functions in general: they wrap up functionality into a single name.
Another benefit is that I can be sure each title will be rendered in exactly the same way. Less text to type for each title means less chance of leaving out part of the formula. This is nice to the programmer, who undoubtedly is eager to find a shortcut to typing long segments of identical HTML. A higher degree of quality is ensured. If a call to the function is mistyped, PHP will display an error. If no errors are displayed, the titles are most likely displayed identically and in the correct format. If the title turns out to need changing, the code must be altered in only one place. This is a good antidote to the painful phrase, "I changed my mind...."
Another similar use of PHP is to dress up what is essentially CGI output: a large block of PHP surrounded by HTML so that the output of the code simply appears in a larger page. This is a similar approach offered by SSI (Server-Side Includes). An SSI tag may call a CGI and insert the output in its place.
The approach is appropriate in situations where your site is mostly static, but certain key areas must be dynamic. The advantage is very low impact on the Web server. PHP is used only when absolutely needed. In Listing 20.2 the code generates information that doesn't change, but it's easy to imagine code that pulls stock quotes from a database. It eliminates the need to edit the HTML page each time the information changes, but parts that don't change often, like the layout of the page, are left as static HTML.
While this is an example of dynamic output, you are often faced with the opposite situation. Your site may be completely static, but you need to accept catalog requests. PHP is a good solution for accepting form submissions. The first step is to create an HTML page that asks for name and address.
The page is a very simple submission form. Each of the input tags will be turned into a PHP variable when the submit button is clicked. A file named req.txt will be opened for appending, and each of the form fields will be written into the file. Each field is separated by tab characters, which allows you to import the file into a spreadsheet easily.
Dressing Up CGI Output<HTML>
The following chart displays the colors safe for displaying in all browsers. These colors should not dither on any computer with a color palette of at least 256 colors. This chart will only display on browsers that support table cell background colors.<?
Catalog Request FormHTML>
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.