Archive for July, 2007

69Chapter 5Syntax and Variablesprint( never_set print value: $never_set ); if (Web hosting uk)

Sunday, July 22nd, 2007

69Chapter 5Syntax and Variablesprint( never_set print value: $never_set
); if ($set_var == $never_set) print( set_var is equal to never_set!
); if (IsSet($set_var)) print( set_var is set.
); elseprint( set_var is not set.
); if (IsSet($never_set)) print( never_set is set.
); elseprint( never_set is not set. ); Oddly enough, this code will produce the following output: set_var print value: 0never_set print value: set_var is equal to never_set! set_var is set. never_set is not set. The variable $never_sethas never been assigned, so it produces an empty string when astring is expected (as in the printstatement) and a zero value when a number is expected(as in the comparison test that concludes that the two variables are the same). Still, IsSetcan tell the difference between $set_varand $never_set. Assigning a variable is not irrevocable the function unset()will restore a variable to anunassigned state (for example, unset($set_var);will make $set_varinto an unbound variable, regardless of its previous assignments). Variable scopeScopeis the technical term for the rules about when a name (for, say, a variable or function) has the same meaning in two different places and in what situations two names spelledexactly the same way can actually refer to different things. Any PHP variable not inside a function has globalscope and extends throughout a given thread of execution. In other words, if you assign a variable near the top of a PHP file, thevariable name has the same meaning for the rest of the file; and if it is not reassigned, it willhave the same value as the rest of your code executes (except inside the body of functions). The assignment of a variable will not affect the value of variables with the same name inother PHP files or even in repeated uses of the same file. For example, let s say that you havetwo files, startup.phpand next_thing.php, which are typically visited in that order by auser. Let s also say that near the top of startup.php, you have the line: $username = Jane Q. User ; which is executed only in certain situations. Now, you might hope that, after setting that variablein startup.php, it would also be preset automatically when the user visited next_thing.php, but no such luck. Each time a PHP page executes, it assigns and reassigns variables as it goes, and those variables disappear at the end of a page s production. Assignments of variables in onefile do not affect variables of the same name in a different file or even in other requests for thesame file. Obviously, there are many situations in which you would like to hold onto information forlonger than it takes to generate a particular Web page. There are a variety of ways you can07
Check Tomcat Web Hosting services for best quality webspace to host your web application.

68Part IPHP: The BasicsIt s conceivable that you (Web and email hosting) will

Sunday, July 22nd, 2007

68Part IPHP: The BasicsIt s conceivable that you will want to actually print the preceding math expression ratherthan evaluate it. You can force PHP to treat a mathematical variable assignment as a string by quoting the expression: $pi = 3 + 0.14159 ; Reassigning variablesThere is no interesting distinction in PHP between assigning a variable for the first time andchanging its value later. This is true even if the assigned values are of different types. Forexample, the following is perfectly legal: $my_num_var = This should be a number hope it s reassigned ; $my_num_var = 5; If the second statement immediately follows the first one, the first statement has essentiallyno effect. Unassigned variablesMany programming languages will object if you try to use a variable before it is assigned; others will let you use it, but if you do you may find yourself reading the random contents ofsome area of memory. In PHP, the default error-reporting setting allows you to use unassignedvariables without errors, and PHP ensures that they have reasonable default values. If you would like to be warned about variables that have not been assigned, you should changethe error-reporting level to E_ALL(the highest level possible) from the default level of errorreporting. You can do this either by including the statement error_reporting(E_ALL); at the top of a script or by changing your php.inifile to set the default level (see Chapters 30and 31). Default valuesVariables in PHP do not have intrinsic types a variable does not know in advance whetherit will be used to store a number or a string of characters. So how does it know what type ofdefault value to have when it hasn t yet been assigned? The answer is that, just as with assigned variables, the type of a variable is interpreteddepending on the context in which it is used. In a situation where a number is expected, anumber will be produced, and this works similarly with character strings. In any context thattreats a variable as a number, an unassigned variable will be evaluated as 0; in any contextthat expects a string value, an unassigned variable will be the empty string (the string that is zero characters long). Checking assignment with IsSetBecause variables do not have to be assigned before use, in some situations you can actuallyconvey information by selectively setting or not setting a variable! PHP provides a functioncalled IsSetthat tests a variable to see whether it has been assigned a value. As the following code illustrates, an unassigned variable is distinguishable even from a vari- able that has been given the default value: $set_var = 0; //set_var has a value//never_set does notprint( set_var print value: $set_var
); Cross- Reference07
From our experience, we can recommend PHP5 Web Hosting services, if you need affordable webhost to host and run your web application.

Web design seattle - 67Chapter 5Syntax and Variablesdifferent result if you take

Sunday, July 22nd, 2007

67Chapter 5Syntax and Variablesdifferent result if you take a single-line comment and replace one of the spaces with an end-of-line character. A more accurate way of putting it is that, after the comments have beenstripped out of the code, PHP code is whitespace insensitive. VariablesThe main way to store information in the middle of a PHP program is by using a variable away to name and hang on to any value that you want to use later. Here are the most important things to know about variables in PHP (more detailed explana- tions will follow): .All variables in PHP are denoted with a leading dollar sign ($). .The value of a variable is the value of its most recent assignment. .Variables are assigned with the =operator, with the variable on the left-hand side andthe expression to be evaluated on the right. .Variables can, but do not need, to be declared before assignment. .Variables have no intrinsic type other than the type of their current value. .Variables used before they are assigned have default values. PHP variables are Perl-likeAll variables in PHP start with a leading $sign just like scalar variables in the Perl scriptinglanguage, and in other ways they have similar behavior (need no type declarations, may bereferred to before they are assigned, and so on). (Perl hackers may need to do no more thanskim the headings of this section, which is really for the rest of us.) After the initial $, variable names must be composed of letters (uppercase or lowercase), digits (0 9), and underscore characters (_). Furthermore, the first character after the $maynot be a number. Declaring variables (or not) This subheading is here simply because programmers from some other languages might belooking for it in languages such as C, C++, and Java, the programmer must declare the nameand type of any variable before making use of it. However in PHP, because types are associ- ated with values rather than variables, no such declaration is necessary the first step inusing a variable is to assign it a value. Assigning variablesVariable assignment is simple just write the variable name, and add a single equal sign (=); then add the expression that you want to assign to that variable: $pi = 3 + 0.14159; // approximatelyNote that what is assigned is the result of evaluating the expression, not the expression itself. After the preceding statement is evaluated, there is no way to tell that the value of $piwascreated by adding two numbers together.
We recommend high quality webhost to host and run your jsp application: christian web host services.

66Part IPHP: The (Most popular web site) BasicsYou can put any kind

Sunday, July 22nd, 2007

66Part IPHP: The BasicsYou can put any kind of statement in a brace-enclosed block, including, say, an ifstatementthat itself has a brace-enclosed block. This means that ifstatements can have other ifstate- ments inside them. In fact, this kind of nesting can be done to an arbitrary number of levels. CommentsA commentis the portion of a program that exists only for the human reader. The very firstthing that a program executor does with program code is to strip out the comments, so theycannot have any effect on what the program does. Comments are invaluable in helping thenext person who reads your code figure out what you were thinking when you wrote it, evenwhen that person is yourself a week from now. PHP drew its inspiration from several different programming languages, most notably C, Perl, and Unix shell scripts. As a result, PHP supports styles of comments from all those languages, and those styles can be intermixed freely in PHP code. C-style multiline commentsThe multilinestyle of commenting is the same as in C: A comment starts with the characterpair /*and terminates with the character pair */. For example: /* This isa comment inPHP */ The most important thing to remember about multiline comments is that they cannot benested. You cannot put one comment inside another. If you try, the comment will be closed off by the first instance of the */character pair, and the rest of what was intended to be anenclosing comment will instead be interpreted as code, probably failing horribly. For example: /* This comment will /* fail horribly on thelast word of this */ sentence*/ This is an easy thing to do unintentionally, usually when you try to deactivate a block of com- mented code by commenting it out. Single-line comments: # and // In addition to the /*…*/multiple-line comments, PHP supports two different ways of com- menting to the end of a given line: one inherited from C++ and Java and the other from Perland shell scripts. The shell-script-style comment starts with a pound sign, whereas the C++ style comment starts with two forward slashes. Both of them cause the rest of the currentline to be treated as a comment, as in the following: # This is a comment, and# this is the second line of the comment// This is a comment too. Each style comments only// one line so the last word of this sentence will failhorribly. The very alert reader might argue that single-line comments are incompatible with what wesaid earlier about whitespace insensitivity. That would be correct you will get a very
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.

65Chapter 5Syntax and VariablesAssignment expressionsA very common kind (Free web space)

Saturday, July 21st, 2007

65Chapter 5Syntax and VariablesAssignment expressionsA very common kind of expression is the assignment, where a variable is set to equal theresult of evaluating some expression. These have the form of a variable name (which alwaysstarts with a $), followed by a single equal sign, followed by the expression to be evaluated. For example: $eight = 2 * (2 * 2) assigns the variable $eightthe value you would expect. An important thing to remember is that even assignment expressions are expressions and sohave values themselves! The value of an expression that assigns a variable is the same as thevalue assigned. This means that you can use assignment expressions in the middle of morecomplicated expressions. If you evaluate the statement: $ten = ($two = 2) + ($eight = 2 * (2 * 2)) each variable would be assigned a numerical value equal to its name. Reasons for expressions and statementsThere are usually only two reasons to write an expression in PHP: for its valueor for a sideeffect. The value of an expression is passed on to any more complicated expression thatincludes it; side effects are anything else that happens as a result of the evaluation. The mosttypical side effects involve assigning or changing a variable, printing something to the user sscreen, or making some other persistent change to the program s environment (such as interacting with a database). Although statements are expressions, they are not themselves included in more complicatedexpressions. This means that the only good reason for a statement is a side effect! It also meansthat it is possible to write legal (yet totally useless statements) such as the second of these: print( Hello ); // side effect is printing to screen2 * 3 + 4; // useless - no side effect$value_num = 3 * 4 + 5; // side effect is assignmentstore_in_database(49.5); // side effect to DBBraces make blocksAlthough statements cannot be combined like expressions, you can always put a sequence ofstatements anywhere a statement can go by enclosing them in a set of curly braces. For example, the ifconstruct in PHP has a test (in parentheses) followed by the statementthat should be executed if the test is true. If you want more than one statement to be exe- cuted when the test is true, you can use a brace-enclosed sequence instead. The followingpieces of code (which simply print a reassuring statement that it is still true that 1 + 2 is equal to 3) are equivalent: if (3 == 2 + 1) print( Good - I haven t totally lost my mind.
); if (3 == 2 + 1) { print( Good - I haven t totally ); print( lost my mind.
); }
Check Tomcat Web Hosting services for best quality webspace to host your web application.

64Part IPHP: The BasicsThe particular ways that operators (Make web site)

Saturday, July 21st, 2007

64Part IPHP: The BasicsThe particular ways that operators group expressions are called precedencerules opera- tors that have higher precedence win in grabbing the expressions around them. If you want, you can memorize the rules, such as the fact that *always has higher precedence than +. Or you can just use the following cardinal rule: When in doubt, use parentheses to groupexpressions. For example: $result1 = 2 + 3 * 4 + 5; // is equal to 19$result2 = (2 + 3) * (4 + 5); // is equal to 45Operator precedence rules remove much of the ambiguity about how subexpressions areassociated. But what about when two operators have the same precedence? Consider thisexpression: $how_much = 3.0 / 4.0 / 5.0; Whether this is equal to 0.15 or 3.75 depends on which division operator gets to grab thenumber 4.0first. There is an exhaustive list of rules of associativity in the online manual, butthe rule to remember is that associativity is usually left-before-right that is, the precedingexpression would evaluate to 0.15, because the leftmost of the two division operators winsthe dispute over precedence. The final wrinkle is order of evaluation, which is not quite the same thing as associativity. Forexample, look at the arithmetic expression: 3 * 4 + 5 * 6We know that the multiplications will happen before the additions, but that is not the sameasknowing which multiplication PHP will perform first. In general, you need not worry aboutevaluation order, because in almost all cases it will not affect the result. You can constructweird examples where the result does depend on order of evaluation, usually by makingassignments in subexpressions that are used in other parts of the expression. For example: $huh = ($this = $that + 5) + ($that = $this + 3); // BADBut don t do this, okay? PHP may or may not have a predictable order of evaluation of expres- sions, but you shouldn t depend on it so we re not going to tell you! (The one legitimate useof relying on left-to-right evaluation order is in short-circuiting Boolean expressions, whichwe cover in Chapter 6.) Expressions and typesUsually, the programmer is careful to match the types of expressions with the operators andfunctions that combine them. Common expressions are mathematical(with mathematicaloperators combining numbers) or Boolean(combining true-or-false statements with ands andors) or string expressions(with operators and functions constructing strings of characters). As with the rest of PHP, however, the treatment of types is surprisingly forgiving. Consider thefollowing expression, which deliberately mixes the types of subexpressions in an inappropri- ate way: 2 + 2 * nonsense + TRUERather than produce an error, this evaluates to the number 3. (You can take this as a puzzlefor now, but we will explain how such a thing can happen in the Types in PHP section of this chapter.)
If you are looking for cheap and quality webhost to host and run your website check Jboss Web Hosting services.

63Chapter 5Syntax and VariablesThe (Cheapest web hosting) different capitalization schemes make

Saturday, July 21st, 2007

63Chapter 5Syntax and VariablesThe different capitalization schemes make for different variables. (Surprisingly, under thedefault settings for error reporting, code like this fragment will not produce a PHP error seethe section Unassigned variables, later in this chapter.) On the other hand, unlike in C, function names are notcase sensitive, and neither are thebasic language constructs (if, then, else, while, and the like). Statements are expressions terminated by semicolonsA statementin PHP is any expressionthat is followed by a semicolon (;). If expressions corre- spond to phrases, statements correspond to entire sentences, and the semicolon is the fullstop at the end. Any sequence of valid PHP statements that is enclosed by the PHP tags is avalid PHP program. Here is a typical statement in PHP, which in this case assigns a string ofcharacters to a variable called $greeting: $greeting = Welcome to PHP! ; The rest of this subsection is about how such statements are built from smaller componentsand how the PHP interpreter handles the evaluation of statements. (If you already feel com- fortable with statements and expressions, feel free to skip ahead.) Expressions are combinations of tokensThe smallest building blocks of PHP are the indivisible tokens, such as numbers (3.14159), strings ( two ), variables ($two), constants (TRUE), and the special words that make up thesyntax of PHP itself (if, else, and so forth). These are separated from each other by whites- pace and by other special characters such as parentheses and braces. The next most complex building block in PHP is the expression, which is any combination of tokens that has a value. A single number is an expression, as is a single variable. Simpleexpressions can also be combined to make more complicated expressions, usually either by putting an operatorin between (for example, 2+(2+2)), or by using them as input to afunction call (for example, pow(2*3,3*2)). Operators that take two inputs go in betweentheir inputs, whereas functions take their inputs in parentheses immediately after theirnames, with the inputs (known as arguments) separated by commas. Expressions are evaluatedWhenever the PHP interpreter encounters an expression in code, that expression is immedi- ately evaluated. This means that PHP calculates values for the smallest elements of theexpression and successively combines those values connected by operators or functions, until it has produced an entire value for the expression. For example, successive steps in animaginary evaluation process might look like: $result = 2 * 2 + 3 * 3 + 5; (= 4 + 3 * 3 + 5) //imaginary evaluation steps(= 4 + 9 + 5) (= 13 + 5) (= 18) with the result that the number 18 is stored in the variable $result. Precedence, associativity, and evaluation orderThere are two kinds of freedom PHP has in expression evaluation: how it groups or associatessubexpressions and the order in which it evaluates them. For example, in the evaluation pro- cess just shown, multiplications were associated more tightly than additions, which affectsthe end result.
From our experience, we can recommend PHP5 Web Hosting services, if you need affordable webhost to host and run your web application.

62Part IPHP: The BasicsPHP syntax is relevant only (Web hosting faq)

Friday, July 20th, 2007

62Part IPHP: The BasicsPHP syntax is relevant only within PHP, so we assume for the rest of this chapter that PHPmode is in force that is, most code fragments will be assumed to be embedded in an HTMLpage and surrounded with the appropriate tags. PHP s Syntax Is C-LikeThe third most important thing to know about PHP syntax is that, broadly speaking, it is likethe C programming language. If you happen to be one of the lucky people who already knowC, this is very helpful; if you are uncertain about how a statement should be written, try itfirst the way you would do it in C, and if that doesn t work, look it up in the manual. The restof this section is for the other people, the ones who don t already know C. (C programmersmight want to skim the headers of this section and also see Appendix A, which is specificallyfor C programmers.) PHP is whitespace insensitiveWhitespaceis the stuff you type that is typically invisible on the screen, including spaces, tabs, and carriage returns (end-of-line characters). PHP s whitespace insensitivity does notmean that spaces and such never matter. (In fact, they are crucial for separating the wordsinthe PHP language.) Instead, it means that it almost never matters how manywhitespace char- acters you have in a row one whitespace character is the same as many such characters. For example, each of the following PHP statements that assigns the sum of 2+2to the vari- able $fouris equivalent: $four = 2 + 2; // single spaces$four =2+2 ; // spaces and tabs$four = 2+ 2; // multiple linesThe fact that end-of-line characters count as whitespace is handy, because it means younever have to strain to make sure that a statement fits on a single line. PHP is sometimes case sensitiveHaving read that PHP isn t picky, you may be surprised to learn that it is sometimes case sensitive (that is, it cares about the distinction between lowercase and capital letters). In particular, all variables are case sensitive. If you embed the following code in an HTML page: ); print( Variable CaPiTaL is $CaPiTaL
); ?> The output you will see is: Variable capital is 67Variable CaPiTaL is07
From our experience, we can recommend PHP5 Web Hosting services, if you need affordable webhost to host and run your web application.

Syntax andVariablesIn this (Most popular web site) chapter, we cover the basic

Friday, July 20th, 2007

Syntax andVariablesIn this chapter, we cover the basic syntax of PHP the rules that allwell-formed PHP code must follow. We explain how to use variablesto store and retrieve information as your PHP code executes and thetype system that governs what kinds of values can be stored in thefirst place. Finally, we look at the simplest ways to display text thatwill show up in your user s browser window. PHP Is ForgivingThe first and most important thing to say about the PHP language isthat it tries to be as forgiving as possible. Programming languagesvary quite a bit in terms of how stringently syntax is enforced. Pickiness can be a goodthing because it helps make sure that thecode you re writing is really what you mean. If you are writing a pro- gram to control a nuclear reactor and you forget to assign a variable, it is far better to have the program be rejected than to create behav- ior different from what you intended. PHP s design philosophy, how- ever, is at the other end of the spectrum. Because PHP started life asa handy utility for making quick-and-dirty Web pages, it emphasizesconvenience for the programmer over correctness; rather than havea programmer do the extra work of redundantly specifying what ismeant by a piece of code, PHP requires the minimum and then triesits best to figure out what was meant. Among other things, thismeans that certain syntactical features that show up in other lan- guages, such as variable declarations and function prototypes, aresimply not necessary. With that said, though, PHP can t read your mind; it has a minimumset of syntactical rules that your code must follow. Whenever you seethe words parseerrorin your browser window instead of the coolWeb page you thought you had just written, it means that you ve bro- ken these rules to the point that PHP has given up on your page. HTML Is Not PHPThe second most important thing to understand about PHP syntax isthat it applies only within PHP. Because PHP is embedded in HTMLdocuments, every part of such a document is interpreted as eitherPHP or HTML, depending on whether that section of the document isenclosed in PHP tags. 55CHAPTER …In This ChapterUnderstanding the basicrules of PHPStoring information variables, and data typesOutput to HTML …
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.

59Chapter 4Adding PHP to HTMLSummaryPHP is easy to (Web hosting provider)

Friday, July 20th, 2007

59Chapter 4Adding PHP to HTMLSummaryPHP is easy to embed in HTML. You can use whatever HTML-production method you realready comfortable with and simply add the PHP sections later. PHP additions can rangefrom simply echoing a single-digit integer to writing long chunks of code. Every PHP block, short or long, is set off by PHP tags. There are several styles of PHP tags, but everyone should be encouraged to use the canonical style. You can also include PHP infiles by using the includefunctions but remember that the contents of the included fileswill not be recognized as PHP unless surrounded by PHP tags. …
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.