Archive for November, 2007

LIGHTENING YOUR WORKLOAD WITH INCLUDES be the same (Post office web site)

Friday, November 16th, 2007

LIGHTENING YOUR WORKLOAD WITH INCLUDES be the same size; PHP inserts the correct width and height attributes in your tag. And with a little extra scripting, you can add a caption to each image. As you work through this chapter you ll learn how PHP includes work, where PHP looks for include files, and how to prevent errors when an include file can t be found. Including code from other files The ability to include code from other files is a core part of PHP. All that s necessary is to use one of PHP s include commands and tell the server where to find the file. Introducing the PHP include commands PHP has four commands that can be used to include code from an external file, namely: include() include_once() require() require_once() They all do basically the same thing, so why have four? Normally, include() is the only command you need. The fundamental difference is that include() attempts to continue processing a script, even if the include file is missing, whereas require() is used in the sense of mandatory: if the file is missing, the PHP engine stops processing and throws a fatal error. The purpose of include_once() and require_once() is to ensure that the external file doesn t reset any variables that may have been assigned a new value elsewhere. Since you normally include an external file only once in a script, these commands are rarely necessary. However, using them does no harm. To show you how to include code from an external file, let s convert the page shown in Figure 4-1. Because the menu and footer appear on every page of the Japan Journey site, they re prime candidates for include files. Here s the code for the body of the page with the menu and footer highlighted in bold.

Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.

Yahoo free web hosting - PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY What

Thursday, November 15th, 2007

PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY What this chapter covers: Using PHP includes for common page elements Protecting sensitive information in include files Automating a you are here menu link Generating a page s title from its filename Automatically updating a copyright notice Displaying random images complete with captions Using the error control operator Using absolute pathnames with PHP includes One of the great payoffs of using PHP is that it can save you a lot of repetitive work. Figure 4-1 shows how four elements of a static web page benefit from a little PHP magic. Figure 4-1. Identifying elements of a static web page that could be improved with PHP The menu and copyright notice appear on each page. Wouldn t it be wonderful if you could make changes to just one page and see them propagate throughout the site in the same way as with CSS? You can with PHP includes. You can even get the menu to display the correct style to indicate which page the visitor is on. Similar PHP wizardry automatically changes the date on the copyright notice and the text in the page title. PHP can also add variety by displaying a random image. JavaScript solutions fail if JavaScript is disabled, but with PHP your script is guaranteed to work all the time. The images don t all need to
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.

Web site traffic - 4 LIGHTENING YOUR WORKLOAD WITH INCLUDES

Wednesday, November 14th, 2007

4 LIGHTENING YOUR WORKLOAD WITH INCLUDES
We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.

PHP SOLUTIONS: DYNAMIC WEB (Web hosting plans) DESIGN MADE EASY Choose

Wednesday, November 14th, 2007

PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY Choose meaningful variable names and remember they re case-sensitive. Use comments to remind you what your script does. Remember that numbers don t require quotes, but strings (text) do. You can use single or double quotes, but the outer pair must match. Use a backslash to escape quotes of the same type inside a string. To store related items together, use an array. Use conditional statements, such as if and if… else, for decision making. Simplify repetitive tasks with loops. Use functions to perform preset tasks. Display PHP output with echo or print. Inspect the content of arrays with print_r(). With most error messages, work backward from the position indicated. Keep smiling and remember that PHP is not difficult.
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.

Adelphia web hosting - HOW TO WRITE PHP SCRIPTS inside functions. This

Tuesday, November 13th, 2007

HOW TO WRITE PHP SCRIPTS inside functions. This isn t always possible, so it s useful to know that functions work like little black boxes and don t normally have any direct impact on the values of variables in the rest of the script. Returning values from functions There s more than one way to get a function to change the value of a variable passed to it as an argument, but the most important method is to use the return keyword, and to assign the result either to the same variable or to another one. This can be demonstrated by amending the doubleIt() function like this: function doubleIt($number) { return $number *= 2; } $num = 4; $doubled = doubleIt($num); echo “$num is: $num
“; echo “$doubled is: $doubled”; You can test this code in functions4.php. The result is shown in the screenshot alongside the code. This time, I have used different names for the variables to avoid confusing them. I have also assigned the result of doubleIt($num) to a new variable. The benefit of doing this is that I now have available both the original value and the result of the calculation. You won t always want to keep the original value, but it can be very useful at times. Where to locate custom-built functions If your custom-built function is in the same page as it s being used, it doesn t matter where you declare the function; it can be either before or after it s used. It s a good idea, however, to store functions together, either at the top or the bottom of a page. This makes them easier to find and maintain. Functions that are used in more than one page are best stored in an external file and included in each page. Including external files with include() and require() is covered in detail in Chapter 4. When functions are stored in external files, you must include the external file before calling any of its functions. PHP quick checklist This chapter contains a lot of information that is impossible to absorb in one sitting, but hopefully the first half has given you a broad overview of how PHP works. Here s a reminder of some of the main points: Always give PHP pages the correct filename extension, normally .php. Enclose all PHP script between the correct tags: . Avoid the short form of the opening tag: We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.

PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY Simply (Java web server)

Monday, November 12th, 2007

PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY Simply putting sayHi(); in a PHP code block results in Hi! being displayed onscreen. This type of function is like a drone: it always performs exactly the same operation. For functions to be responsive to circumstances, you need to pass values to them as arguments (or parameters). Passing values to functions Let s say you want to adapt the sayHi() function so that it displays someone s name. You do this by inserting a variable between the parentheses in the function declaration. The same variable is then used inside the function to display whatever value is passed to the function. To pass more than one variable to a function, separate them with commas inside the opening parentheses. This is how the revised function looks (see functions2.php): function sayHi($name) { echo “Hi, $name!”; } You can now use this function inside a page to display the value of any variable passed to sayHi(). For instance, if you have an online form that saves someone s name in a variable called $visitor, and Chris visits your site, you give him the sort of personal greeting shown alongside by putting sayHi($visitor); in your page. A downside of PHP s weak typing is that if Chris is being particularly uncooperative, he might type 5 into the form instead of his name, giving you not quite the type of high five you might have been expecting. This illustrates why it s so important to check user input before using it in any critical situation. It s also important to understand that variables inside a function remain exclusive to the function. This example should illustrate the point (see functions3.php): function doubleIt($number) { $number *= 2; echo “$number
“; } $number = 4; doubleIt($number); echo $number; If you view the output of this code in a browser, you may get a very different result from what you expect. The function takes a number, doubles it, and displays it onscreen. Line 5 of the script assigns the value 4 to $number. The next line calls the function and passes it $number as an argument. The function processes $number and displays 8. After the function comes to an end, $number is displayed onscreen by echo. This time, it will be 4 and not 8. This example demonstrates that the variable $number that has been declared inside the function is limited in scope to the function itself. The variable called $number in the main script is totally unrelated to the one inside the function. To avoid confusion, it s a good idea to use variable names in the rest of your script that are different from those used
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.

Free php web host - HOW TO WRITE PHP SCRIPTS This next example

Monday, November 12th, 2007

HOW TO WRITE PHP SCRIPTS This next example uses the $book associative array from the Creating arrays section earlier in the chapter and incorporates the key and value of each element into a simple string, as shown in the screenshot (see book.php): foreach ($book as $key => $value) { echo “The value of $key is $value
“; } The foreach keyword is one word. Inserting a space between for and each doesn t work. 3 Breaking out of a loop To bring a loop prematurely to an end when a certain condition is met, insert the break keyword inside a conditional statement. As soon as the script encounters break, it exits the loop. To skip an iteration of the loop when a certain condition is met, use the continue keyword. Instead of exiting, it returns to the top of the loop and executes the next iteration. Modularizing code with functions Functions offer a convenient way of running frequently performed operations. In addition to the large number of built-in functions, PHP lets you create your own. The advantages are that you write the code only once, rather than needing to retype it everywhere you need it. This not only speeds up your development time, but also makes your code easier to read and maintain. If there s a problem with the code in your function, you update it in just one place rather than hunting through your entire site. Moreover, functions usually speed up the processing of your pages. Building your own functions in PHP is very easy. You simply wrap a block of code in a pair of curly braces and use the function keyword to name your new function. The function name is always followed by a pair of parentheses. The following admittedly trivial example demonstrates the basic structure of a custom-built function (see functions1.php in the download files for this chapter): function sayHi() { echo ‘Hi!’; }
In case you need quality webspace to host and run your web applications, try our personal web hosting services.

PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY The (Free web hosting services)

Sunday, November 11th, 2007

PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY The following code does exactly the same as the previous while loop, displaying every number from 1 to 100 (see forloop.php): for ($i = 1; $i <= 100; $i++) { echo "$i
“; } The three expressions inside the parentheses control the action of the loop (note that they are separated by semicolons, not commas): The first expression shows the starting point. You can use any variable you like, but the convention is to use $i. When more than one counter is needed, $j and $k are frequently used. The second expression is a test that determines whether the loop should continue to run. This can be a fixed number, a variable, or an expression that calculates a value. The third expression shows the method of stepping through the loop. Most of the time, you will want to go through a loop one step at a time, so using the increment (++) or decrement (–) operator is convenient. There is nothing stopping you from using bigger steps. For instance, replacing $i++ with $i+=10 in the previous example would display 1, 11, 21, 31, and so on. Looping through arrays with foreach The final type of loop in PHP is used exclusively with arrays. It takes two forms, both of which use temporary variables to handle each array element. If you only need to do something with the value of each array element, the foreach loop takes the following form: foreach (array_name as temporary_variable) { do something with temporary_variable } The following example loops through the $shoppingList array and displays the name of each item, as shown in the screenshot (see shopping_list.php): $shoppingList = array(’wine’, ‘fish’, . ‘bread’, ‘grapes’, ‘cheese’); foreach ($shoppingList as $item) { echo $item.’
‘; } Although the preceding example uses an indexed array, you can also use it with an associative array. However, the alternative form of the foreach loop is of more use with associative arrays, because it gives access to both the key and value of each array element. It takes this slightly different form: foreach (array_name as key_variable => value_variable) { do something with key_variable and value_variable }
From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.

HOW TO WRITE PHP SCRIPTS Loops using while (Multiple domain web hosting)

Saturday, November 10th, 2007

HOW TO WRITE PHP SCRIPTS Loops using while and do… while The simplest type of loop is called a while loop. Its basic structure looks like this: while (condition is true) { do something } The following code displays every number from 1 through 100 in a browser (you can test it in while.php in the download files for this chapter). It begins by setting a variable ($i) to 1, and then using the variable as a counter to control the loop, as well as display the current number onscreen. $i = 1; // set counter while ($i <= 100) { echo "$i
“; $i++; // increase counter by 1 } A variation of the while loop uses the keyword do and follows this basic pattern: do { code to be executed } while (condition to be tested); The only difference between a do… while loop and a while loop is that the code within the do block is executed at least once, even if the condition is never true. The following code (in dowhile.php) displays the value of $i once, even though it s greater than the maximum expected. $i = 1000; do { echo “$i
“; $i++; // increase counter by 1 } while ($i <= 100); The danger with while and do... while loops is forgetting to set a condition that brings the loop to an end, or setting an impossible condition. When this happens, you create an infinite loop that either freezes your computer or causes the browser to crash. The versatile for loop The for loop is less prone to generating an infinite loop because you are required to declare all the conditions of the loop in the first line. The for loop uses the following basic pattern: for (initialize counter; test; increment) { code to be executed }
We recommend high quality webhost to host and run your jsp application: christian web host services.

PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY The (Web server logs)

Saturday, November 10th, 2007

PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY The main points to note about switch are as follows: The expression following the case keyword must be a number or a string. You can t use comparison operators with case. So case > 100: isn t allowed. Each block of statements should normally end with break, unless you specifically want to continue executing code within the switch statement. You can group several instances of the case keyword together to apply the same block of code to them. If no match is made, any statements following the default keyword will be executed. If no default has been set, the switch statement will exit silently and continue with the next block of code. Using the conditional operator The conditional operator (?:) is a shorthand method of representing a simple conditional statement. The basic syntax looks like this: condition ? value if true : value if false; Here is an example of it in use: $age = 17; $fareType = $age > 16 ? ‘adult’ : ‘child’; The second line tests the value of $age. If it s greater than 16, $fareType is set to adult, otherwise $fareType is set to child. The equivalent code using if… else looks like this: if ($age > 16) { $fareType = ‘adult’; } else { $fareType = ‘child’; } The if… else version is easier to read, but the conditional operator is more compact. Most beginners hate this shorthand, but once you get to know it, you ll realize how convenient it can be. Because it uses three operands, it s sometimes called the ternary operator. Creating loops As the name suggests, a loop is a section of code that is repeated over and over again until a certain condition is met. Loops are often controlled by setting a variable to count the number of iterations. By increasing the variable by one each time, the loop comes to a halt when the variable gets to a preset number. The other way loops are controlled is by running through each item of an array. When there are no more items to process, the loop stops. Loops frequently contain conditional statements, so although they re very simple in structure, they can be used to create code that processes data in often sophisticated ways.
You want to have a cheap webhost for your apache application, then check apache web hosting services.