Page 145 - Open Soource Technologies 304.indd
P. 145

Open Source Technologies



                   Notes                 \r               Line feed.
                                         \$               Escape $ sign so that it is not treated as a variable
                                                          but as the character $.
                                         \ {Octal #}      The character represented by the specified octal #—for
                                                          example.\70 represents the letter 8.
                                         \X{Hexadecima #}  The character represented by the specified hexadecimal
                                                          #—for example, \0×32 represents the letter 2.

                                 An additional feature of double-quoted strings is that certain notations of variables and expressions
                                 can be embedded directly within them. Without going into specifics, here are some examples of
                                 legal strings that embed variables. The references to variables are automatically replaced with
                                 the variables’ values, and if the values aren’t strings, they are converted to their corresponding
                                 string  representations  (for  example,  the  integer  123  would  be  first  converted  to  the  string
                                 “123”).
                                 “The result is $result\n”

                                 “The array offset $i contains $arr[$i]”

                                 In cases, where you’d like to concatenate strings with values (such as variables and expressions)
                                 and this syntax isn’t sufficient, you can use the . (dot) operator to concatenate two or more
                                 strings. This operator is covered in a later section.

                                 Single Quotes in addition to double quotes, single quotes may also delimit strings. However,
                                 in contrast to double quotes, single quotes do not support all the double quotes’ escaping and
                                 variable substitution.

                                 The following table includes the only two escapings supported by single quotes:

                                         \’            Single quote.
                                         \\            Backslash,  used  when wanting  to represent  a  backslash
                                                       followed by a single quote—for example.\\’.

                                       Example:   ‘Hello, World’
                                                ‘Today\’s the day’

                                 Here-Docs Here-docs  enable  you  to  embed  large  pieces  of  text  in  your  scripts,  which  may
                                 include lots of double quotes and single quotes, without having to constantly escape them. The
                                 following is an example of a here-doc:

                                 <<<THE_END
                                 PHP stands for “PHP: Hypertext Preprocessor”.

                                 The acronym “PHP” is therefore, usually referred to as a recursive acronym
                                 | →because the long form contains the acronym itself.

                                 As this text is being written in a here-doc there is no need to escape the
                                 | →double quotes.

                                 THE_END




        140                               LOVELY PROFESSIONAL UNIVERSITY
   140   141   142   143   144   145   146   147   148   149   150