Archive for November, 2007

HOW TO WRITE (Yahoo web space) PHP SCRIPTS so testing stops

Friday, November 9th, 2007

HOW TO WRITE PHP SCRIPTS so testing stops as soon as one turns out to be false. Similarly, when using ||, only one condition needs to be fulfilled, so testing stops as soon as one turns out to be true. $a = 10; $b = 25; if ($a > 5 && $b > 20) // returns true if ($a > 5 || $b > 30) // returns true, $b never tested The implication of this is that when you need all conditions to be met, you should design your tests with the condition most likely to return false as the first to be evaluated. When you need just one condition to be fulfilled, place the one most likely to return true first. If you want a particular set of conditions considered as a group, enclose them in parentheses. if (($a > 5 && $a < 8) || ($b > 20 && $b < 40)) PHP also uses AND in place of && and OR in place of ||. However, they aren t exact equiv- alents. To avoid problems, it s advisable to stick with && and ||. Using the switch statement for decision chains The switch statement offers an alternative to if... else for decision making. The basic structure looks like this: switch(variable being tested) { case value1: statements to be executed break; case value2: statements to be executed break; default: statements to be executed } The case keyword indicates possible matching values for the variable passed to switch(). When a match is made, every subsequent line of code is executed until the break keyword is encountered, at which point the switch statement comes to an end. A simple example follows: switch($myVar) { case 1: echo '$myVar is 1'; break; case 'apple': echo '$myVar is apple'; break; default: echo '$myVar is neither 1 nor apple'; }
From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.

PHP SOLUTIONS: (Top web site) DYNAMIC WEB DESIGN MADE EASY Table

Thursday, November 8th, 2007

PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY Table 3-5. Continued Symbol Name Use !== Not identical Determines whether the values are not identical (according to the same criteria as the previous operator). > Greater than Determines whether the value on the left is greater than the one on the right. >= Greater than or equal to Determines whether the value on the left is greater than or equal to the one on the right. < Less than Determines whether the value on the left is less than the one on the right. <= Less than or equal to Determines whether the value on the left is less than or equal to the one on the right. When comparing two values, you must always use the equality operator (==), the iden- tical operator (===), or their negative equivalents (!= and !==). A single equal sign assigns a value; it doesn t perform comparisons. Testing more than one condition Frequently, comparing two values is not enough. PHP allows you to set a series of conditions using logical operators to specify whether all, or just some, need to be fulfilled. The most important logical operators in PHP are listed in Table 3-6. Negation testing that the opposite of something is true is also considered a logical operator, although it applies to individual conditions rather than a series. Table 3-6. The main logical operators used for decision making in PHP Symbol Name Use && Logical AND Evaluates to true if both conditions are true || Logical OR Evaluates to true if either is true; otherwise, returns false ! Negation Tests whether something is not true Technically speaking, there is no limit to the number of conditions that can be tested. Each condition is considered in turn from left to right, and as soon as a defining point is reached, no further testing is carried out. When using &&, every condition must be fulfilled,
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.

HOW TO WRITE PHP SCRIPTS $OK = false; (Yahoo web space)

Thursday, November 8th, 2007

HOW TO WRITE PHP SCRIPTS $OK = false; if ($OK) { // do something } The code inside the conditional statement won t be executed, because $OK is false. Implicit Boolean values Using implicit Boolean values provides a convenient shorthand, although it has the disadvantage at least to beginners of being less clear. Implicit Boolean values rely on PHP s relatively narrow definition of what it regards as false, namely: The case-insensitive keywords false and null Zero as an integer (0), a floating-point number (0.0), or a string (’0′ or “0″) An empty string (single or double quotes with no space between them) An empty array An object with no values or functions Everything else is true. This definition explains why “false” (in quotes) is interpreted by PHP as true. Making decisions by comparing two values Most true/false decisions are based on a comparison of two values using comparison operators. Decisions are based on whether two values are equal, whether one is greater than the other, and so on. Table 3-5 lists the comparison operators used in PHP. Table 3-5. PHP comparison operators used for decision making Symbol Name Use == Equality Returns true if the values are equal; otherwise, returns false. != Inequality Returns true if the values are different; otherwise, returns false. === Identical Determines whether both values are identical. To be considered identical, they must not only have the same value, but also be of the same data type (e.g., both floating-point numbers). Continues
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.

PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY Always (Web design careers)

Wednesday, November 7th, 2007

PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY Always use print_r() to inspect arrays; echo and print don t work. To display the con- tents of an array in a web page, use a foreach loop, as described later in the chapter. The truth according to PHP Decision making in PHP conditional statements is based on the mutually exclusive Boolean values, true and false. If the condition equates to true, the code within the conditional block is executed. If false, it s ignored. Whether a condition is true or false is determined in one of the following ways: A variable set explicitly to one of the Boolean values A value PHP interprets implicitly as true or false The comparison of two non-Boolean values Explicit Boolean values This is straightforward. If a variable is assigned the value true or false, and then used in a conditional statement, the decision is based on that value. As stated in the first half of this chapter, true and false are case-insensitive and must not be enclosed in quotes, for example:
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.

HOW TO WRITE PHP SCRIPTS To (Ftp web hosting) create an

Tuesday, November 6th, 2007

HOW TO WRITE PHP SCRIPTS To create an empty array, simply use array() with nothing between the parentheses, like this: $shoppingList = array(); The $shoppingList array now contains no elements. If you add a new one using $shoppingList[], it will automatically start numbering again at 0. Multidimensional arrays Array elements can store any data type, including other arrays. For instance, the $book array holds details of only one book. It might be more convenient to create an array of arrays in other words, a multidimensional array containing details of several books, like this: $books = array( array( ‘title’ => ‘PHP Solutions: Dynamic Web Design Made Easy’, ‘author’ => ‘David Powers’, ‘publisher’ => ‘friends of ED’, ‘ISBN’ => ‘1-59059-731-1′), array( ‘title’ => ‘Beginning PHP and MySQL 5′, ‘author’ => ‘W. Jason Gilmore’, ‘publisher’ => ‘Apress’, ‘ISBN’ => ‘1-59059-552-1′) ); This example shows associative arrays nested inside an indexed array, but multidimensional arrays can nest either type. To refer to a specific element use the key of both arrays, for example: $books[1][’author’] // value is ‘W. Jason Gilmore’ Working with multidimensional arrays isn t as difficult as it first looks. The secret is to use a loop to get to the nested array. Then you can work with it in the same way as an ordinary array. This is how you handle the results of a database search, which is normally contained in a multidimensional array. Using print_r() to inspect an array To inspect the content of an array during testing, pass the array to print_r() like this (see inspect_array2.php): print_r($books); The following screenshot shows how PHP displays a multidimensional array; load inspect_array1.php into a browser to see how print_r() outputs the contents of an ordinary array. Often, it helps to switch to Source view to inspect the details, as browsers ignore indenting in the underlying output.
If you are in need for cheap and reliable webhost to host your website, we recommend http web server services.

PHP SOLUTIONS: DYNAMIC WEB (Cool web site) DESIGN MADE EASY Using

Tuesday, November 6th, 2007

PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY Using array() to build an indexed array Instead of declaring each array element individually, you declare the variable name once, and assign all the elements by passing them as a comma-separated list to array(), like this: $shoppingList = array(’wine’, ‘fish’, ‘bread’, ‘grapes’, ‘cheese’); The comma must go outside the quotes, unlike American typographic practice. For ease of reading, I have inserted a space following each comma, but it s not necessary to do so. PHP numbers each array element automatically, beginning from 0, so this creates exactly the same array as if you had numbered them individually. To add a new element to the end of the array, use a pair of empty square brackets like this: $shoppingList[] = ‘coffee’; PHP simply uses the next number available, so this becomes $shoppingList[5]. Using array() to build an associative array The shorthand way of creating an associative array uses the => operator (an equal sign followed by a greater-than sign) to assign a value to each array key. The basic structure looks like this: $arrayName = array(’key1′ => ‘element1′, ‘key2′ => ‘element2′); So, this is the shorthand way to build the $book array: $book = array(’title’ => ‘PHP Solutions: Dynamic Web Design . Made Easy’, ‘author’ => ‘David Powers’, ‘publisher’ => ‘friends of ED’, ‘ISBN’ => ‘1-59059-731-1′); It s not essential to align the => operators like this, but it makes code easier to read and maintain. Using array() to create an empty array There are two reasons you might want to create an empty array, as follows: To create an array so that it s ready to have elements added to it inside a loop (this is known as initializing an array) To clear all elements from an existing array
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.

HOW TO WRITE PHP SCRIPTS $_COOKIE = array_map(’stripslashes_deep’, (Affordable web hosting)

Monday, November 5th, 2007

HOW TO WRITE PHP SCRIPTS $_COOKIE = array_map(’stripslashes_deep’, $_COOKIE); } } The code for this function is included in corefuncs.php in the download files for this book. To use the function, add the following code immediately after the opening PHP tag on any page where it is needed: include(’path/to/file/corefuncs.php’); nukeMagicQuotes(); The value of path/to/file should be a relative path to corefuncs.php. Alternatively, use the technique described in PHP Solution 4-8 in the next chapter to establish a full path to the file. Using a dynamically generated full path allows you to use the same code in any page, regardless of its position in the site folder hierarchy. The nukeMagicQuotes() function is not the ideal solution, because it involves removing the magic quotes, rather than preventing them from being inserted in the first place. However, it is the only universally applicable one. It also has the advantage that your pages will continue to run smoothly even if the server administrator decides to turn off magic quotes. Creating arrays As explained earlier, there are two types of arrays: indexed arrays, which use numbers to identify each element, and associative arrays, which use strings. You can build both types by assigning a value directly to each element. Let s take another look at the $book associative array: $book[’title’] = ‘PHP Solutions: Dynamic Web Design Made Easy’; $book[’author’] = ‘David Powers’; $book[’publisher’] = ‘friends of ED’; $book[’ISBN’] = ‘1-59059-731-1′; To build an indexed array the direct way, use numbers instead of strings. Indexed arrays are numbered from 0, so to build the $shoppingList array depicted in Figure 3-3, you declare it like this: $shoppingList[0] = ‘wine’; $shoppingList[1] = ‘fish’; $shoppingList[2] = ‘bread’; $shoppingList[3] = ‘grapes’; $shoppingList[4] = ‘cheese’; Although both are perfectly valid ways of creating arrays, it s a nuisance to have to type out the variable name each time, so there s a much shorter way of doing it. The method is slightly different for each type of array.
Check Tomcat Web Hosting services for best quality webspace to host your web application.

Windows 2003 server web - PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY backslash,

Sunday, November 4th, 2007

PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY backslash, so they invented magic quotes. In some respects, it was good magic; it went a long way toward solving some security problems for beginners. Unfortunately, it created new problems, most notably the proliferation of backslashes in the middle of dynamically generated text. After a lot of heated argument, it was finally decided to remove magic quotes from PHP 6. Although magic quotes are enabled by default in earlier versions of PHP, server administrators have the option to turn them off. So the only sensible approach to this period of change is a strategy that assumes magic quotes are off, but removes backslashes if the server still inserts them. To find out whether your remote server has magic quotes on or off, upload a PHP page containing the single-line script that you used in the previous chapter to display your PHP configuration. Load the page into a browser, and check the PHP Core section near the top. Find the line indicated in the following screenshot. If the value of magic_quotes_gpc is Off, you can run all the scripts in this book without taking further measures. You should also change the setting of magic_quotes_gpc to Off in php.ini in your local testing environment. For security reasons, it s advisable to delete the phpinfo()page or move it to a password- protected folder after checking your remote server s settings. Leaving the script on a publicly accessible page exposes details about your site that malicious users might try to exploit. If the value of magic_quotes_gpc is On, you need to use the following custom-built function, nukeMagicQuotes(), which I have adapted from a solution in the PHP online documentation. It checks the value of magic quotes and strips out any backslashes if necessary, leaving you with clean data. function nukeMagicQuotes() { if (get_magic_quotes_gpc()) { function stripslashes_deep($value) { $value = is_array($value) ? array_map(’stripslashes_deep’, . $value) : stripslashes($value); return $value; } $_POST = array_map(’stripslashes_deep’, $_POST); $_GET = array_map(’stripslashes_deep’, $_GET);
We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.

HOW TO WRITE (Web hosting account) PHP SCRIPTS Assigning a string

Sunday, November 4th, 2007

HOW TO WRITE PHP SCRIPTS Assigning a string to a variable using heredoc involves the following steps: 1. Type the assignment operator, followed by <<< and an identifier. The identifier can be any combination of letters, numbers, and the underscore, as long as it doesn t begin with a number. 2. Begin the string on a new line. It can include both single and double quotes. Any variables will be processed in the same way as in a double-quoted string. 3. Place the identifier on a new line after the end of the string. Nothing else should be on the same line, except for a final semicolon. Moreover, the identifier must be at the beginning of the line; it cannot be indented. It s a lot easier when you see it in practice. The following simple example can be found in heredoc.php in the download files for this chapter: $fish = 'whiting'; $mockTurtle = <<< Gryphon "Will you walk a little faster?" said a $fish to a snail. "There's a porpoise close behind us, and he's treading on my tail." Gryphon; echo $mockTurtle; In this example, Gryphon is the identifier. The string begins on the next line, and the double quotes are treated as part of the string. Everything is included until you reach the identifier at the beginning of a new line. As you can see from the following screenshot, the heredoc displays the double quotes and processes the $fish variable. To achieve the same effect without using the heredoc syntax, you need to add the double quotes and escape them like this: $fish = 'whiting'; $mockTurtle = ""Will you walk a little faster?" said a $fish to a . snail. "There's a porpoise close behind us, and he's treading on my tail."" echo $mockTurtle; This is only a short example. The heredoc syntax is mainly of value when you have a long string and/or lots of quotes. Unraveling the magic quotes tangle Several years ago, the developers of PHP decided it would be a lot easier to handle quotes if input from online forms and certain other sources were escaped automatically with a
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.

PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY Using (Web host sites)

Saturday, November 3rd, 2007

PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY Using escape sequences inside double quotes Double quotes have another important effect: they treat escape sequences in a special way. All escape sequences are formed by placing a backslash in front of a character. Most of them are designed to avoid conflicts with characters that are used with variables, but three of them have special meanings: n inserts a new line character, r inserts a carriage return, and t inserts a tab. Table 3-4 lists the main escape sequences supported by PHP. Table 3-4. The main PHP escape sequences Escape sequence Character represented in double-quoted string ” Double quote n New line r Carriage return t Tab \ Backslash $ Dollar sign { Opening curly brace } Closing curly brace [ Opening square bracket ] Closing square bracket The escape sequences listed in Table 3-4, with the exception of \, work only in double- quoted strings. If you use them in a single-quoted string, they will be treated as a literal backslash followed by the second character. Avoiding the need to escape quotes with heredoc syntax Using a backslash to escape one or two quotation marks isn t a great burden, but I frequently see examples of code where backslashes seem to have run riot. It must be difficult to type, and it s certainly difficult to read. However, it s totally unnecessary. The PHP heredoc syntax offers a relatively simple method of assigning text to a variable without the need for any special handling of quotes. The name heredoc is derived from here-document, a technique used in Unix and Perl programming to pass large amounts of text to a command.
If you are in need for cheap and reliable webhost to host your website, we recommend http web server services.