139Chapter 8StringsYou can retrieve the individual characters of (Windows 2003 server web)
139Chapter 8StringsYou can retrieve the individual characters of a string by including the number of the charac- ter, starting at 0, enclosed in curly braces immediately following a string variable. These characters will actually be one-character strings. For example, the following code: $my_string = Doubled ; for ($index = 0; $index < 7; $index++) { $string_to_print = $my_string{$index}; print( $string_to_print$string_to_print ); } gives the browser output: DDoouubblleeddwith each character of the string being printed twice per loop. (The number 7 is hard-codedin this example only because we haven t yet covered how to find out the length of a string see the function strlen()in the later section Inspecting strings. ) In earlier versions of PHP, it was customary to retrieve individual characters of a string usingsquare brackets to enclose the index rather than curly braces (for example, $my_string[3] rather than $my_string{3}). While you can still use the square (array-like) brackets to dothis, this usage is now deprecated, and the curly brace syntax is encouraged. String operatorsPHP offers only one real operator on strings: the dot (.) or concatenation operator. Thisoperator, when placed between two string arguments, produces a new string that is the resultof putting the two strings together in sequence. For example: $my_two_cents = I want to give you a piece of my mind ; $third_cent = And another thing ; print($my_two_cents . ... . $third_cent); gives the browser output: I want to give you a piece of my mind ... And another thingNote that we are not passing multiple string arguments to the print statement we are hand- ing it one string argument, which was created by concatenating three strings together. Thefirst and third strings are variables, but the middle one is a literal string enclosed in doublequotes. Note that the concatenation operator is not +as in Java, and it does not overload anythingelse. If you forget this and add strings using +, they will be interpreted as numbers, with theresult that one + two equals 0(because no successful string-to-number conversion canbe made). Concatenation and assignmentJust as with arithmetic operators, PHP has a shorthand operator (.=) that combines concate- nation with assignment. The following statement: $my_string_var .= $new_addition; is exactly equivalent to: $my_string_var = $my_string_var . $new_addition; NoteCaution10
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.