String Operators


PHP has two string operators. The first is the concatenation operator (.), which we've seen before, which joins its right and left operands into one string. The second is the concatenating assignment operator (.=), which appends the operand on the right side to the operand on the left side.

You can see an example of each in pphpstringop.php, Example 2-4.

Example 2-4. Using the string operators, pphpstringop.php
 <HTML>     <HEAD><TITLE>The string operators</TITLE></HEAD>     <BODY>         <H1>The string operators</H1> <?php $a = "No "; echo "\$a = ", $a, "<BR>"; echo "\$b = \$a . \"problem \"<BR>"; $b = $a . "problem ";  echo "Now \$b = ", $b, "<BR>"; echo "\$b .= \"at all.\"<BR>"; $b .= "at all.";      echo "Now \$b = ", $b, "<BR>"; ?>       </BODY> </HTML> 

The results of this example appear in Figure 2-5. (For more on strings, take a look at all the PHP string functions available in Chapter 3.)

Figure 2-5. The string operators.




    Spring Into PHP 5
    Spring Into PHP 5
    ISBN: 0131498622
    EAN: 2147483647
    Year: 2006
    Pages: 254

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net