Web design - 79Chapter 5Syntax and VariablesAnd the browser displays the

79Chapter 5Syntax and VariablesAnd the browser displays the preceding output in exactly that order. This is because antelope is spliced into the string $saved_string, before the $animalvariable is reas- signed. In addition to splicing variable values into doubly quoted strings, PHP also replacessome special multiple-character escape sequenceswith their single-character values. Themost commonly used is the end-of-line sequence ( n ) in reading a string like: The first line nnnThe fourth line Variable interpolationWhenever an unescaped $symbol appears in a doubly quoted string, PHP tries to interpretwhat follows as a variable name and splices the current value of that variable into the string. Exactly what kind of substitution occurs depends on how the variable is set: .If the variable is currently set to a string value, that string is interpolated (or spliced) into the doubly quoted string. .If the variable is currently set to a nonstring value, the value is converted to a string, and then that string value is interpolated. .If the variable is not currently set, PHP interpolates nothing (or, equivalently, PHPsplices in the empty string). An example: $this = this ; $that = that ; $the_other = 2.2000000000; print( $this,$not_set,$that+$the_other
); produces the PHP outputthis,,that+2.2
which in turn, when seen in a browser, looks like: this,,that+2.2If you find any part of this example puzzling, it is worth working through exactly what PHPdoes to parse the string in the printstatement. First, notice that the string has four $signs, each of which is interpreted as starting a variable name. These variable names terminate atthe first occurrence of a character that is not legal in a variable name. Legal characters areletters, numbers, and underscores; the illegalterminating characters in the preceding printstring are (in order) a comma, another comma, the plus symbol (+), and a left angle bracket(<). The first two variables are bound to strings ( this and that ), so those strings arespliced in literally. The next variable ($not_set) has never been assigned, so it is omittedentirely from the string under construction. Finally, the last variable ($the_other) is discov- ered to be bound to a double that value is converted to a string ( 2.2 ), which is thenspliced into our constructed string. For more about converting numbers to strings, see the Assignment and Coercion section inChapter 25. As we said earlier in this chapter, all this interpretation of doubly quoted strings happenswhen the string is read,not when it is printed. If we saved the example string in a variableand printed it out later, it would reflect the variable values in the preceding code even if thevariables had been changed in the meantime. Cross- Reference07
Note: If you are looking for high quality webhost to host and run your jsp application check Vision jsp web hosting services

Leave a Reply