Archive for July, 2007

89Chapter 6Control and FunctionsIf-elseThe syntax for ifis: if (Web hosting asp)

Tuesday, July 31st, 2007

89Chapter 6Control and FunctionsIf-elseThe syntax for ifis: if (test) statement-1Or with an optional elsebranch: if (test) statement-1elsestatement-2When an ifstatement is processed, the testexpression is evaluated, and the result is inter- preted as a Boolean value. If testis true, statement-1is executed. If testis not true, andthere is an elseclause, statement-2is executed. If test is false, and there is no elseclause, execution simply proceeds with the next statement after the ifconstruct. Note that a statementin this syntax can be a single statement that ends with a semicolon, abrace-enclosed block of statements, or another conditional construct (which itself counts asa single statement). Conditionals can be nested inside each other to arbitrary depth. Also, theBoolean expression can be a genuine Boolean (TRUE, FALSE, or the result of a Boolean opera- tor or function), or it can be a value of another type interpreted as a Boolean. For the full story on how values of non-Boolean types are treated as Booleans, see Chapter 25. The short version is that the number 0, the string 0 , and the empty string, , are false, andalmost every other value is true. The following example, which prints a statement about the absolute difference betweentwonumbers, shows both the nesting of conditionals and the interpretation of the test asaBoolean: if ($first - $second) if ($first > $second) { $difference = $first - $second; print( The difference is $difference
); } else{ $difference = $second - $first; print( The difference is $difference
); } elseprint( There is no difference
); This code relies on the fact that the number 0is interpreted as a false value if the differ- ence is zero, then the test fails, and the no differencemessage is printed. If there is a difference, a further test is performed. (This example is artificial, because a test like $first!=$secondwould accomplish the same thing comprehensibly.) Cross- Reference08
In case you need quality webspace to host and run your web applications, try our personal web hosting services.

88Part IPHP: The BasicsAs we will see, this (Fedora web server)

Tuesday, July 31st, 2007

88Part IPHP: The BasicsAs we will see, this is equivalent to: if ($first_num > $second_num) $max_num = $first_num; else$max_num = $second_num; but is somewhat more concise. BranchingThe two main structures for branching are if and switch. Ifis a workhorse and is usuallythe first conditional structure anyone learns. Switchis a useful alternative for certain situa- tions where you want multiple possible branches based on a single value and where a seriesof ifstatements would be cumbersome. Comparing Things That Are Not IntegersAlthough comparison operators work with numbers or strings, a couple of gotchas lurk here. First of all, although it is always safe to do less-than or greater-than comparisons on doubles (or even between doubles and integers), it can be dangerous to rely on equality comparisons ondoubles, especially if they are the result of a numerical computation. The problem is that arounding error may make two values that are theoretically equal differ slightly. Second, although comparison operators work for strings as well as numbers, PHP s automatictype conversions can lead to counterintuitive results when the strings are interpretable as numbers. For example, the code: $string_1 = 00008 ; $string_2 = 007 ; $string_3 = 00008-OK ; if ($string_2 < $string_1) print( $string_2 is less than $string_1
); if ($string_3 < $string_2) print( $string_3 is less than $string_2
); if ($string_1 < $string_3) print( $string_1 is less than $string_3
); gives this output (with comments added): 007 is less than 00008 // numerical comparison00008-OK is less than 007 // string comparison00008 is less than 00008-OK // string comp. - contradiction! When it can, PHP will convert string arguments to numbers, and when both sides can be treatedthat way, the comparison ends up being numerical, not alphabetic. The PHP designers view thisas a feature, not a bug. Our view is that if you are comparing strings that have any chance ofbeing interpreted as numbers, you re better off using the strcmp()function (see Chapter 10).
If you are looking for cheap and quality webhost to host and run your website check Jboss Web Hosting services.

Web servers - 87Chapter 6Control and FunctionsWatch out for a very

Monday, July 30th, 2007

87Chapter 6Control and FunctionsWatch out for a very common mistake: confusing the assignment operator (=) with the com- parison operator (==). The statement if($three=$four).will (probably unexpectedly) set the variable $threeto be the same as $four; what s more, the test will be true if $fouris a true value! Operator precedenceAlthough overreliance on precedence rules can be confusing for the person who reads yourcode next, it s useful to note that comparison operators have higher precedence than Booleanoperators. This means that a test like the following: if ($small_num > 2 && $small_num < 5) ... doesn t need any parentheses other than those shown. String comparisonThe comparison operators may be used to compare strings as well as numbers (see the cautionary sidebar). We would expect the following code to print its associated sentence(with apologies to Billy Bragg): if (( Marx < Mary ) and( Mary < Marzipan )) { print( Between Marx and Marzipan in the ); print( dictionary, there was Mary.
); } The comparisons are case sensitive, and the only reason that this example will print anythingis because our values are case-consistent.Because of the capitalization of Dennis, the follow- ing will not print anything: if (( deep blue sea < Dennis ) and( Dennis < devil )) { print( Between the deep blue sea and ); print( the devil, that was me.
); } The ternary operatorOne especially useful construct is the ternary conditional operator, which plays a role some- where between a Boolean operator and a true branching construct. Its job is to take threeexpressions and use the truth value of the first expression to decide which of the other twoexpressions to evaluate and return. The syntax looks like: test-expression ? yes-expression : no-expressionThe value of this expression is the result of yes-expressionif test-expressionis true; otherwise, it is the same as no-expression. For example, the following expression assigns to $max_numeither $first_numor$second_num, whichever is larger: $max_num = $first_num > $second_num ? $first_num : $second_num; Caution08
From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.

Web page design - 86Part IPHP: The BasicsSo far, all we ve formally

Monday, July 30th, 2007

86Part IPHP: The BasicsSo far, all we ve formally covered are the TRUEand FALSEconstants and how to combinethem to make other true-or-false values. Now we ll move on to operators that actually let youmake meaningful Boolean tests. Comparison operatorsTable 6-2 shows the comparison operators, which can be used for either numbers or strings(although you should see the cautionary sidebar entitled Comparing Things That Are NotIntegers ). Table 6-2: Comparison OperatorsOperatorNameBehavior==EqualTrue if its arguments are equal to each other, falseotherwise!=Not equalFalse if its arguments are equal to each other, trueotherwiseGreater thanTrue if the left-hand argument is greater than itsright-hand argument, but false otherwise<=Less than or equal toTrue if the left-hand argument is less than its right- hand argument or equal to it, but false otherwise>=Greater than or equal toTrue if the left-hand argument is greater than its right- hand argument or equal to it, but false otherwise===IdenticalTrue if its arguments are equal to each other and ofthe same type, but false otherwise As an example, here are some variable assignments, followed by a compound test that isalways true: $three = 3; $four = 4; $my_pi = 3.14159; if (($three == $three) and($four === $four) and($three != $four) and($three < $four) and($three <= $four) and($four >= $three) and($three <= $three) and($my_pi > $three) and($my_pi <= $four)) print( My faith in mathematics is restored!
); elseprint( Sure you typed that right?
);
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.

85Chapter 6Control and FunctionsThe &&and (Make a web site) ||operators will be

Sunday, July 29th, 2007

85Chapter 6Control and FunctionsThe &&and ||operators will be familiar to C programmers. The !operator is usually callednot, since it negates the argument it operates on. As an example of using logical operators, consider the following expression: (($statement_1 && $statement_2) || ($statement_1 && !$statement_2) || (!$statement_1 && $statement_2) || (!$statement_1 && !$statement_2)) This is a tautology, meaning that it is always true regardless of the values of the statementvariables. There are four possible combinations of truth values for the two variables, each of which is represented by one of the &&expressions. One of these four must be true, andbecause they are linked by the ||operator, the entire expression must be true. Here s another, slightly trickier tautology using xor: (($statement_1 and $statement_2 and$statement_3) xor((!($statement_1 and $statement_2)) or(!($statement_1 and $statement_3)) or(!($statement_2 and $statement_3)))) In English, this expression says, Given three statements, one and only one of the followingtwo things hold either 1) all three statements are true, or 2) there are two statements thatare not both true. Precedence of logical operatorsJust as with any operators, some logical operators have higher precedence than others, although precedence can always be overridden by grouping subexpressions using parenthe- ses. The logical operators listed in declining order of precedence are: !, &&, ||, and, xor, or. Actually, and, xor, and orhave much lower precedence than the others, so that the assign- ment operator (=) binds more tightly than and, but less tightly than &&. A complete table of operator precedence and associativity can be found in the online manualat www.php.net. Logical operators short-circuitOne very handy feature of Boolean operators is that they associate left to right, and theyshort-circuit, meaning that they do not even evaluate their second argument if their truthvalue is unambiguous from their first argument. For example, imagine that you wanted todetermine a very approximate ratio of two numbers, but also wanted to avoid a possible division-by-zero error. You can first test to make sure that the denominator is not zero byusing the !=(not-equal-to) operator: if ($denom != 0 && $numer / $denom > 2) print( More than twice as much! ); In the case where $denomis zero, the &&operator should return false regardless of whetherthe second expression is true or false. Because of short-circuiting, the second expression isnot evaluated, so an error is avoided. In the case where $denomis not zero, the &&operatordoes not have enough information to reach a conclusion about its truth value, so the secondexpression is evaluated. Cross- Reference08
We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.

84Part IPHP: The BasicsIn this chapter, (Adelphia web hosting) we also

Sunday, July 29th, 2007

84Part IPHP: The BasicsIn this chapter, we also look at how to use the large body of functions already provided inPHP and then, a bit later, how to define your own functions. Luckily, there is no real differencebetween using a built-in function and using your own functions. But first, let s discuss control. Boolean ExpressionsEvery control structure in this chapter has two distinct parts: the test(which determineswhich part of the rest of the structure executes), and the dependent codeitself (whether sepa- rate branches or the body of a loop). Tests work by evaluating a Boolean expression, anexpression with a result treated as either true or false. Boolean constantsThe simplest kind of expression is a simple value, and the simplest Boolean values are theconstants TRUEand FALSE. We can use these constants anywhere we would use a more com- plicated Boolean expression, and vice versa. For example, we can embed them in the test partof an if-elsestatement: if (TRUE) print( This will always print
); elseprint( This will never print
); Or equivalently: if (FALSE) print( This will never print
); elseprint( This will always print
); Logical operatorsLogical operatorscombine other logical (aka Boolean) values to produce new Boolean values. The standard logical operations (and, or, not, and exclusive-or) are supported by PHP, which has alternate versions of the first two, as shown in Table 6-1. Table 6-1: Logical OperatorsOperatorBehaviorandIs true if and only if both of its arguments are true. orIs true if either (or both) of its arguments are true. !Is true if its single argument (to the right) is false and false if its argument is true. xorIs true if either (but not both) of its arguments are true. &&Same as and, but binds to its arguments more tightly. (See the discussion ofprecedence later in the chapter.) ||Same as orbut binds to its arguments more tightly.
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.

Yahoo web hosting - Control andFunctionsIt s difficult to write interesting programs if

Saturday, July 28th, 2007

Control andFunctionsIt s difficult to write interesting programs if you can t make thecourse of program execution depend on anything. In a weak sense, the behavior of code that prints variables depends on the variablevalues, but that is as exciting as filling out a template. As program- mers, we want programs that react to something (the world, the timeof day, user input, or the contents of a database) by doing somethingdifferent. This kind of program reaction requires a control structure,which indi- cates how different situations should lead to the execution of differ- ent code. In Chapter 5, we informally used the ifcontrol structurewithout really explaining it; in this chapter, we lay out every kind ofcontrol structure offered by PHP and study their workings in detail. Experienced C programmers: Of all the features in PHP, control isprobably the most reliably C-like all the structures you are usedto are here, and they work the same way. The two broad types of control structures we will talk about arebranchesand loops.A branch is a fork in the road for a program s exe- cution depending on some test or other, the program goes eitherleft or right, possibly following a different path for the rest of the pro- gram s execution. A loop is a special kind of branch where one of theexecution paths jumps back to the beginning of the branch, repeatingthe test and possibly the body of the loop. Before we can make interesting use of control structures, however, we have to be able to construct interesting tests. We ll start from thevery simplest of tests, working our way up from the constants TRUEand FALSEand then move on to using these tests in more compli- cated code. Any real programming language has some kind of capability for proce- dural abstraction a way to name pieces of code so that you can usethem as building blocks in writing other pieces of code. Some script- ing languages lack this capability, and we can tell you from our ownsorrowful experience that complex server-side code can quicklybecome unmanageable without it. PHP s mechanism for this kind of abstraction is the function.Thereare really two kinds of functions in PHP those that have been builtinto the language by the PHP developers and those defined by indi- vidual PHP programmers. Note66CHAPTER …In This ChapterBoolean expressionsBranchingLoopingTerminating executionExceptionsUsing functionsFunction documentationDefining your ownfunctionsFunctions and variablescopeFunction scope …
We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.

How to cite a web site - 82Part IPHP: The Basicswill produce the following output

Saturday, July 28th, 2007

82Part IPHP: The Basicswill produce the following output in the browser: The antelope has 1 head(s). The antelope has 4 leg(s). The values for the variables we included in the string have been neatly spliced into the printedoutput. This makes it very easy to quickly produce Web pages with content that varies depend- ing on how variables have been set. It is not the result of any magical properties of print, however the magic is really happening in the interpretation of the quoted string itself. HTML and linebreaksOne mistake often made by new PHP programmers (especially those from a C background) isto try to break lines of text in their browsers by putting end-of-line characters ( n ) in thestrings they print. To understand why this doesn t work, you have to distinguish the outputofPHP (which is usually HTML code, ready to be sent over the Internet to a browser program) from the way that output is rendered by the user s browser. Most browser programs willmake their own choices about how to split up lines in HTML text, unless you force a linebreak with the
tag. End-of-line characters in strings will put line breaks in the HTMLsource that PHP sends to your user s browser (which can still be useful for creating readableHTML source), but they will usually have no effect on the way that text looks in a Web page. SummaryPHP code follows a basic set of syntactical rules, mostly borrowed from programming lan- guages such as C and Perl. The syntactical requirements of PHP are minimal, and in generalPHP tries to display results when it can rather than generating an error. PHP has eight types: integer, double, Boolean, NULL, string, array, object, and resource. Fiveof these are simple types: Integers are whole numbers, doubles are floating-point numbers, Booleans are true-or-false values, NULL has just one value (NULL), and strings are sequencesof characters. Arraysare a compound type that holds other PHP values, indexed either byintegers or by strings. Objectsare instances of programmer-defined classes, which can con- tain both member variables and member functions, and which can inherit functions and datatypes from other classes. (We address arrays in Chapter 9 and objects in Chapter 20.) Finally, resourcesare special references to memory allocated from external programs, which memoryPHP frees automatically when they are no longer needed (we cover resources in Chapter 25). Only values are typed in PHP variables have no inherent type other than the value of theirmost recent assignment. PHP automatically converts value types as demanded by the contextin which the value is used. The programmer can also explicitly control types by means ofboth conversion functions and type casts. PHP code is whitespace insensitive, and although variable names are case sensitive, basiclanguage constructs and function names are not. Simple PHP expressions are combined intolarger expressions by operators and function calls, and statements are expressions with a ter- minating semicolon. Variables are denoted by a leading $character and are assigned usingthe =operator. They need no type declarations and have reasonable default values if usedbefore they are assigned. Variable scope is global except inside the body of functions, whereit is local to the function unless explicitly declared otherwise. The simplest way to send output to the user is by using either echoor print, which outputtheir string arguments. They are particularly useful in combination with doubly quotedstrings, which automatically replace embedded variables with their values. …
You want to have a cheap webhost for your apache application, then check apache web hosting services.

Web host - 81Chapter 5Syntax and VariablesBoth of these statements will

Friday, July 27th, 2007

81Chapter 5Syntax and VariablesBoth of these statements will cause the given sentence to be displayed, without displayingthe quote signs. (Note for C programmers:Think of the HTTP connection to the user as thestandard output stream for these functions.) You can also give multiple arguments to the unparenthesized version of echo, separated bycommas, as in: echo This will print in the , user s browser window. ; The parenthesized version, however, will not accept multiple arguments: echo ( This will produce a , PARSE ERROR! ); PrintThe command printis very similar to echo, with two important differences: .Unlike echo, printcan accept only one argument. .Unlike echo, printreturns a value, which represents whether the printstatementsucceeded. The value returned by printwill be 1if the printing was successful and 0if unsuccessful. (It is rare that a syntactically correct printstatement will fail, but in theory this return valueprovides a means to test, for example, if the user s browser has closed the connection.) Both echoand printare usually used with string arguments, but PHP s type flexibility meansthat you can throw pretty much any type of argument at them without causing an error. Forexample, the following two lines will print exactly the same thing: print( 3.14159 ); // print a stringprint(3.14159); // print a numberTechnically, what is happening in the second line is that, because printexpects a stringargument, the floating-point version of the number is converted to a string value beforeprintgets hold of it. However, the effect is that both printand echowill reliably print outnumbers as well as string arguments. For the sake of simplicity and uniformity, we will typically use the parenthesized version ofprintin our examples, rather than using echo. In addition to the printing functions discussed here, there are two printing functions usedmostly for debugging: print_r()and var_dump(). The point of these functions is to helpyou visualize what s going on with compound data structures like arrays, so we cover themalong with the details of arrays in Chapter 9. Variables and stringsC programmers are accustomed to using a function called printf, which allows you to splicevalues and expressions into a specially formatted printing string. PHP has analogous func- tions (which we will cover in Chapter 7), but as it turns out we can get much of the samefunctionality just by using print(or echo) with quoted strings. For example, the fragment: $animal = antelope ; $animal_heads = 1; $animal_legs = 4; print( The $animal has $animal_heads head(s).
); print( The $animal has $animal_legs leg(s).
); Cross- Reference07
From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.

Disney web site - 80Part IPHP: The BasicsIn addition to single-quotes and

Friday, July 27th, 2007

80Part IPHP: The BasicsIn addition to single-quotes and double-quotes, there is another way to create strings (calledthe heredocsyntax), which in some ways makes it even easier to splice in the values of vari- ables. We cover it in Chapter 8. Newlines in stringsAlthough PHP offers an escape sequence (n) for newline characters, it is good to know thatyou can literally include new lines in the middle of strings, which PHP also treats as a newlinecharacters. This capability turns out to be convenient when creating HTML strings, becausebrowsers will ignore the line breaks anyway, so we can format our strings with line breaks tomake our PHP code lines short: print( My HTML page is too bigto fit on a single line, but that doesn t mean that Ineed multiple print statements! ); We produced this statement in our text editor by literally hitting the Enter key at the end of thefirst two lines these newlines are preserved in the string, so the single printstatement willproduce three distinct lines of PHP output. (Your mileage may vary depending on your text editor if your editor automatically wraps lines in displaying them, you may see three lines ofcode that are actually one long line.) Of course, the browser program will ignore these newlinesand will make its own decisions about whether and where to break the lines in display, but youwill see the linebreaks if you use View Source in your browser to see the HTML itself. LimitsThere are no artificial limits on string length within the bounds of available memory, youought to be able to make arbitrarily long strings. OutputMost of the constructs in the PHP language execute silently they don t print anything tooutput. The only way that your embedded PHP code will display anything in a user s browserprogram is either by means of statements that print something to output or by calling func- tions that, in turn, call printstatements. Echo and printThe two most basic constructs for printing to output are echoand print. Their language status is somewhat confusing, because they are basic constructs of the PHP language, ratherthan being functions. As a result, they can be used either with parentheses or without them. (Function calls always have the name of the function first, followed by a parenthesized list ofthe arguments to the function.) EchoThe simplest use of echois to print a string as argument, for example: echo This will print in the user s browser window. ; Or equivalently: echo( This will print in the user s browser window. ); Cross- Reference07
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.