Archive for October, 2007

Web hosting - PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY Weak

Wednesday, October 31st, 2007

PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY Weak typing is a mixed blessing. It makes PHP very easy for beginners, but it means you often need to check that a variable contains the correct data type before using it. Doing calculations with PHP PHP is highly adept at working with numbers and can perform a wide variety of calculations, from simple arithmetic to complex math. This reference section covers only the standard arithmetic operators. See www.php.net/manual/en/ref.math.php for details of the mathematical functions and constants supported by PHP. Arithmetic operators The standard arithmetic operators all work the way you would expect, although some of them look slightly different from those you learned at school. For instance, an asterisk (*) is used as the multiplication sign, and a forward slash (/) is used to indicate division. Table 3-1 shows examples of how the standard arithmetic operators work. To demonstrate their effect, the following variables have been set: $x = 20; $y = 10; $z = 4.5; Table 3-1. Arithmetic operators in PHP Operation Operator Example Result Addition + $x + $y 30 Subtraction -$x - $y 10 Multiplication * $x * $y 200 Division / $x / $y 2 Modulo division % $x % $z 2 Increment (adds 1) ++ $x++ 21 Decrement (subtracts 1) $y-9 The modulo operator returns the remainder of a division, as follows: 26 % 5 // result is 1 26 % 27 // result is 26 10 % 2 // result is 0
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.

Web design software - HOW TO WRITE PHP SCRIPTS Most of the

Tuesday, October 30th, 2007

HOW TO WRITE PHP SCRIPTS Most of the time, this is very convenient, although it does mean that you need to be careful with user input. You may expect a user to enter a number in a form, but PHP won t object if it encounters a word instead. Checking user input carefully is one of the major themes of later chapters. Even though PHP is weakly typed, it uses the following eight data types: Integer: This is a whole number, such as 1, 25, 42, or 2006. Integers must not con tain any commas or other punctuation as thousand-separators. You can also use hexadecimal numbers, which should be preceded by 0x (e.g., 0xFFFFFF, 0×000000). Floating-point number: This is a number that contains a decimal point, such as 9.99, 98.6, or 2.1. Like integers, floating-point numbers must not contain thousand- separators. (This type is also referred to as float or double.) String: A string is text of any length. It can be as short as zero characters (an empty string), and it has no upper limit. Boolean: This type has only two values: true or false. See The truth according to PHP later in this chapter for details of what PHP regards as true and false. Array: An array is a variable that is capable of storing multiple values, although it may contain none at all (an empty array). Arrays can hold any data type, including other arrays. An array of arrays is called a multidimensional array. See Creating arrays later in this chapter for details of how to populate an array with values. Object: PHP has powerful object-oriented capabilities, which are mainly of interest to advanced users. Objects are covered only briefly in this book when connecting to a database with the MySQL Improved extension or PHP Data Objects (PDO). Resource: When PHP connects to an external data source, such as a file or data base, it stores a reference to it as a resource. NULL: This is a special data type that indicates that a variable has no value. An important side effect of PHP s weak typing is that, if you enclose an integer or floating- point number in quotes, PHP automatically converts it from a string to a number, allowing you to perform calculations without the need for any special handling. This is different from JavaScript and ActionScript, and it can have unexpected consequences. When PHP sees the plus sign (+), it assumes that you want to perform addition, and it tries to convert strings to integers or floating-point numbers, as in the following example (the code is in data_conversion1.php in the download files for this chapter): $fruit = ‘2 apples’; $veg = ‘ 2 carrots’; echo $fruit + $veg; // displays 4 PHP sees that both $fruit and $veg begin with a number, so it extracts the number and ignores the rest. However, if the string doesn t begin with a number, PHP converts it to 0, as shown in this example (the code is in data_conversion2.php): $fruit = ‘2 apples’; $veg = ‘ and 2 carrots’; echo $fruit + $veg; // displays 2
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.

PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY (Crystaltech web hosting) There

Tuesday, October 30th, 2007

PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY There is a fifth type of error: strict, which was introduced in PHP 5.0.0, mainly for the benefit of advanced developers. Strict error messages warn you about the use of depre- cated code or techniques that aren t recommended. As of this writing, strict error mes- sages are not displayed by default, but there are plans to change this as a prelude to removing outdated parts of the language. The idea is to warn you that anything that generates a strict error in PHP 6 will generate a fatal error in the next major version, PHP 7. This policy is in the early stages of development, so it may change, but if you see a strict error message, ignore it at your peril. None of the code in this book generates strict error messages in the version of PHP current at the time of this writing (5.1.4). Now, on with the show . . . Your head is probably reeling by now, but believe it or not you have covered all the fundamentals of PHP. Of course, there are a lot more details, many of which are described in the reference section that follows. However, rather than plowing straight on, I suggest you take a short break and then move on to the next chapter. Come back to the next section when you ve gained some practical experience of working with PHP, as it will make much more sense then. Also, the idea of this book is to put PHP to work and provide real solutions for your websites. The projects in each chapter use progressively more advanced techniques, so if you re new to PHP, cut your teeth on them first before plunging into working with a database. PHP: A quick reference This part of the chapter is intended to provide a quick source of information on PHP basics. It makes no attempt to cover every aspect of PHP syntax. For that, you should refer to the PHP documentation at www.php.net/manual/en or a more detailed reference book, such as Beginning PHP and MySQL 5: From Novice to Professional, Second Edition by W. Jason Gilmore (Apress, ISBN: 1-59059-552-1). Using PHP in an existing website There is no problem mixing .html and .php pages in the same website. However, PHP code will be processed only in files that have the .php filename extension, so it s a good idea to give the same extension to all your pages, even if they don t all contain dynamic features. That way, you have the flexibility to add PHP to pages without breaking existing links or losing search engine rankings. Data types in PHP PHP is what s known as a weakly typed language. What this means in practice is that, unlike some other computer languages (e.g., Java or C#), PHP doesn t care what type of data you store in a variable.
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check mysql web server services.

HOW TO WRITE PHP SCRIPTS (Disney web site) than a decimal

Monday, October 29th, 2007

HOW TO WRITE PHP SCRIPTS than a decimal point. PHP will choke if you feed it numbers that contain commas (or any thing else) as the thousands separator. Understanding PHP error messages There s one final thing you need to know about before savoring the delights of PHP: error messages. They re an unfortunate fact of life, but it helps a great deal if you understand what they re trying to tell you. The following illustration shows the structure of a typical error message. The first thing to realize about PHP error messages is that they report the line where PHP discovered a problem. Most newcomers quite naturally assume that s where they ve got to look for their mistake. Wrong . . . What PHP is telling you most of the time is that something unexpected has happened. In other words, the mistake lies before that point. The preceding error message means that PHP discovered an echo command where there shouldn t have been one. (Error messages always prefix PHP elements with T_, which stands for token. Just ignore it.) Instead of worrying what might be wrong with the echo command (probably nothing), start working backward, looking for anything that might be missing. Usually, it s a semicolon or closing quote on a previous line. There are four main categories of error, presented here in descending order of importance: Fatal error: Any XHTML output preceding the error will be displayed, but once the error is encountered as the name suggests everything else is killed stone dead. A fatal error is normally caused by referring to a nonexistent file or function. Parse error: This means there s a mistake in your code, such as mismatched quotes, or a missing semicolon or closing brace. Like a fatal error, it stops the script in its tracks and doesn t even allow any XHTML output to be displayed. Warning: This alerts you to a serious problem, such as a missing include file. (Include files are the subject of Chapter 4.) However, the error is not serious enough to prevent the rest of the script from being executed. Notice: This advises you about relatively minor issues, such as the use of deprecated code or a nondeclared variable. Although this type of error won t stop your page from displaying (and you can turn off the display of notices), you should always try to eliminate them. Any error is a threat to your output.
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.

Free web hosting services - PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY You

Sunday, October 28th, 2007

PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY You can use echo with variables, numbers, and strings. Simply put it in front of whatever you want to display, like this: $name = ‘David’; echo $name; // displays David echo 5; // displays 5 echo ‘David’; // displays David The important thing to remember about echo and print, when using them with a variable, is that they work only with variables that contain a single value. You cannot use them to display the contents of an array or of a database result. This is where loops are so useful: you use echo or print inside the loop to display each element individually. You will see plenty of examples of this in action throughout the rest of the book. You may see scripts that use parentheses with echo and print, like this: echo(’David’); // displays David The parentheses make absolutely no difference. Unless you enjoy typing purely for the sake of it, I suggest you leave them out. Joining strings together PHP has a rather unusual way of joining strings (text). Although many other computer languages use the plus sign (+), PHP uses a period, dot, or full stop (.) like this: $firstName = ‘David’; $lastName = ‘Powers’; echo $firstName.$lastName; // displays DavidPowers As the comment in the final line of code indicates, when two strings are joined like this, PHP leaves no gap between them. Don t be fooled into thinking that adding a space after the period will do the trick. It won t. You can put as much space on either side of the period as you like; the result will always be the same, because PHP ignores whitespace in code. You must either include a space in one of the strings or insert the space as a string in its own right, like this: echo $firstName.’ ‘.$lastName; // displays David Powers The period or concatenation operator, to give it its correct name can be difficult to spot among a lot of other code. Make sure the font size in your script editor is large enough to read without straining to see the difference between periods and commas. Working with numbers PHP can do a lot with numbers from simple addition to complex math. The second half of this chapter contains details of the arithmetic operators you can use with PHP. All you need to remember at the moment is that numbers mustn t contain any punctuation other
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.

HOW TO WRITE PHP SCRIPTS and much, much (Web hosting reviews)

Saturday, October 27th, 2007

HOW TO WRITE PHP SCRIPTS and much, much more. You can identify functions in PHP code because they re always followed by a pair of parentheses. Sometimes the parentheses are empty, as in the case of phpversion(), which you used in phptest.php in the previous chapter. Often, though, the parentheses contain variables, numbers, or strings, like this line of code from the script in Figure 3-1: $thisYear = date(’Y'); This calculates the current year and stores it in the variable $thisYear. It works by feeding the string ‘Y’ to the built-in PHP function date(). Placing a value between the parentheses like this is known as passing an argument to a function. The function takes the value in the argument and processes it to produce (or return) the result. For instance, if you pass the string ‘M’ as an argument to date() instead of ‘Y’, it will return the current month as a three-letter abbreviation (e.g., Mar, Apr, May). As the following example shows, you capture the result of a function by assigning it to a suitably named variable: $thisMonth = date(’M'); The date() function is covered in depth in Chapter 14. Some functions take more than one argument. When this happens, separate the arguments with commas inside the parentheses, like this: $mailSent = mail($to, $subject, $message); It doesn t take a genius to work out that this sends an email to the address stored in the first argument, with the subject line stored in the second argument, and the message stored in the third one. You ll see how this function works in Chapter 5. You ll often come across the term parameter in place of argument. There is a tech- nical difference between the two words, but for all practical purposes, they are inter- changeable. As if the 3,000-odd built-in functions weren t enough, PHP lets you build your own custom functions. Even if you don t relish the idea of creating your own, throughout this book you ll use some that I have made. You use them in exactly the same way. Displaying PHP output There s not much point in all this wizardry going on behind the scenes unless you can display the results in your web page. There are two ways of doing this in PHP: using echo or print. There are some subtle differences between the two, but they are so subtle, you can regard them as identical. I prefer echo for the simple reason that it s one fewer letter to type.
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: DYNAMIC WEB DESIGN MADE EASY you (Ftp web hosting)

Saturday, October 27th, 2007

PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY you can adopt any style you like. The important thing is to be consistent so that you can spot anything that looks out of place. The limited width of the printed page means that I normally use just two spaces to indent code in this book, but most people find that tabbing four or five spaces makes for the most readable code. Perhaps the biggest difference in styles lies in the way individual developers arrange curly braces. I align the closing brace with the block of code it concludes. Other writers use this style: if ($bytes > 51200) { // display error message and abandon upload } else { // continue upload } Yet others use this style: if ($bytes > 51200) { // display error message and abandon upload } else { // continue upload } Choose whichever style you re most comfortable with. As long as it s consistent and easy to read, that s all that matters. Using loops for repetitive tasks Loops are huge time-savers because they perform the same task over and over again, yet involve very little code. They re frequently used with arrays and database results. You can step through each item one at a time looking for matches or performing a specific task. Loops are particularly powerful in combination with conditional statements, allowing you to perform operations selectively on a large amount of data in a single sweep. Loops are best understood by working with them in a real situation, but details of all looping structures, together with examples, are in the second half of this chapter. Using functions for preset tasks As I mentioned earlier, functions do things . . . lots of things, mind-bogglingly so in PHP. The last time I counted, PHP had nearly 3,000 built-in functions, and more have been added since. Don t worry: you ll only ever need to use a handful, but it s reassuring to know that PHP is a full-featured language capable of industrial-strength applications. The functions you ll be using in this book do really useful things, such as get the height and width of an image, create thumbnails from existing images, query a database, send email,
You want to have a cheap webhost for your apache application, then check apache web hosting services.

Top ten web hosting - HOW TO WRITE PHP SCRIPTS An alternative decision-making

Friday, October 26th, 2007

HOW TO WRITE PHP SCRIPTS An alternative decision-making structure, the switch statement, is described in the second half of this chapter. Making comparisons Conditional statements are interested in only one thing: whether the condition being tested equates to true. If it s not true, it must be false. There s no room for half- measures or maybes. Conditions often depend on the comparison of two values. Is this bigger than that? Are they both the same? And so on. To test for equality, PHP uses two equal signs (==) like this: if ($status == ‘administrator’) { // send to admin page } else { // refuse entry to admin area } Don t use a single equal sign in the first line like this: if ($status = ‘administrator’) { Doing so will open the admin area of your website to everyone. Why? Because this auto- matically sets the value of $status to administrator; it doesn t compare the two val- ues. To compare values, you must use two equal signs. It s an easy mistake to make, but one with potentially disastrous consequences. Size comparisons are performed using the mathematical symbols for less than (<) and greater than (>). Let s say you re checking the size of a file before allowing it to be uploaded to your server. You could set a maximum size of 50KB like this: if ($bytes > 51200) { // display error message and abandon upload } else { // continue upload } You can test for two or more conditions simultaneously. Details are in the second half of this chapter. Using indenting and whitespace for clarity Indenting code helps to keep statements in logical groups, making it easier to understand the flow of the script. There are no fixed rules; PHP ignores any whitespace inside code, so
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.

PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY (My web site) Confusion

Thursday, October 25th, 2007

PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY Confusion alert: I mentioned earlier that statements must always be followed by a semi- colon. This applies only to the statements (or commands) inside the curly braces. Although called a conditional statement, this decision-making pattern is one of PHP s control structures, and it shouldn t be followed by a semicolon. Think of the semicolon as a command that means do it. The curly braces surround the command statements and keep them together as a group. The code inside the curly braces is executed only if the condition is true. If it s false, PHP ignores everything between the braces and moves on to the next section of code. How PHP determines whether a condition is true or false is described in the following section. Sometimes, the if statement is all you need, but you often want a default action to be invoked. To do this, use else, like this: if (condition is true) { // code to be executed if condition is true } else { // default code to run if condition is false } What if you want more alternatives? One way is to add more if statements. PHP will test them, and as long as you finish with else, at least one block of code will run. However, it s important to realize that all if statements will be tested, and the code will be run in every single one where the condition equates to true. If you want only one code block to be executed, use elseif like this: if (condition is true) { // code to be executed if first condition is true } elseif (second condition is true) { // code to be executed if first condition fails // but second condition is true else { // default code to run if both conditions are false } You can use as many elseif clauses in a conditional statement as you like. It s important to note that only the first one that equates to true will be executed; all others will be ignored, even if they re also true. This means you need to build conditional statements in the order of priority that you want them to be evaluated. It s strictly a first-come, first- served hierarchy. Although elseifis normally written as one word, you can use else ifas separate words.
We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.

Msn web hosting - HOW TO WRITE PHP SCRIPTS As the next

Thursday, October 25th, 2007

HOW TO WRITE PHP SCRIPTS As the next section explains, PHP makes decisions on the basis of whether something eval uates to true or false. Putting quotes around false has surprising consequences. The fol lowing code: $OK = false; does exactly what you expect: it makes $OK false. Now take a look at this: $OK = ‘false’; This does exactly the opposite of what you might expect: it makes $OK true! Why? Because the quotes around false turn it into a string, and PHP treats strings as true. (There s a more detailed explanation in The truth according to PHP in the second half of this chapter.) The other thing to note about true, false, and null is that they are case-insensitive. The following examples are all valid: $OK = TRUE; $OK = tRuE; $OK = true; So, to recap: PHP treats true, false, and null as special cases. Don t enclose them in quotes. They are case-insensitive. Making decisions Decisions, decisions, decisions . . . Life is full of decisions. So is PHP. They give it the ability to display different output according to circumstances. Decision making in PHP uses con ditional statements. The most common of these uses if and closely follows the structure of normal language. In real life, you may be faced with the following decision (admittedly not very often if you live in Britain): If the weather’s hot, I’ll go to the beach. In PHP pseudo-code, the same decision looks like this: if (the weather’s hot) { I’ll go to the beach; } The condition being tested goes inside parentheses, and the resulting action goes between curly braces. This is the basic decision-making pattern: if (condition is true) { // code to be executed if condition is true }
If you are in need for cheap and reliable webhost to host your website, we recommend http web server services.