Sophie

Sophie

distrib > Mandriva > 2008.1 > x86_64 > by-pkgid > ebb1914cf182a88528b4547490db1dd8 > files > 1607

kdewebdev-quanta-doc-3.5.9-2mdv2008.1.x86_64.rpm

<HTML
><HEAD
><TITLE
>Strings</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.44"><LINK
REL="HOME"
TITLE="PHP Manual"
HREF="manual.html"><LINK
REL="UP"
TITLE="Types"
HREF="language.types.html"><LINK
REL="PREVIOUS"
TITLE="Floating point numbers"
HREF="language.types.double.html"><LINK
REL="NEXT"
TITLE="Arrays"
HREF="language.types.array.html"></HEAD
><BODY
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>PHP Manual</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="language.types.double.html"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Chapter 6. Types</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="language.types.array.html"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="sect1"
><H1
CLASS="sect1"
><A
NAME="language.types.string"
>Strings</A
></H1
><P
>&#13;    Strings can be specified using one of two sets of delimiters.
   </P
><P
>&#13;    If the string is enclosed in double-quotes ("), variables within
    the string will be expanded (subject to some parsing
    limitations). As in C and Perl, the backslash ("\") character can
    be used in specifying special characters:
    <DIV
CLASS="table"
><P
><B
>Table 6-1. Escaped characters</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><TR
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>sequence</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>meaning</TH
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="literal"
>\n</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>newline</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="literal"
>\r</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>carriage</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="literal"
>\t</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>horizontal tab</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="literal"
>\\</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>backslash</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="literal"
>\$</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>dollar sign</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="literal"
>\"</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>double-quote</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="literal"
>\[0-7]{1,3}</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13;         the sequence of characters matching the regular
         expression is a character in octal notation
        </TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><TT
CLASS="literal"
>\x[0-9A-Fa-f]{1,2}</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>&#13;         the sequence of characters matching the regular
         expression is a character in hexadecimal notation
        </TD
></TR
></TABLE
></DIV
></P
><P
>&#13;    You can escape any other character, but a warning will be issued
    at the highest warning level.
   </P
><P
>&#13;    The second way to delimit a string uses the single-quote ("'")
    character. When a string is enclosed in single quotes, the only
    escapes that will be understood are "\\" and "\'". This is for
    convenience, so that you can have single-quotes and backslashes in
    a single-quoted string. Variables will <I
CLASS="emphasis"
>not</I
> be
    expanded inside a single-quoted string.
   </P
><P
>&#13;    Another way to delimit strings is by using here doc syntax
    ("&#60;&#60;&#60;").  One should provide an identifier after
    <TT
CLASS="literal"
>&#60;&#60;&#60;</TT
>, then the string, and then the
    same identifier to close the quotation. The closing identifier
    <I
CLASS="emphasis"
>must</I
> begin in the first column of the line.
    <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><P
><B
>Example 6-1. Here doc string quoting example</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="programlisting"
>  1&nbsp;
  2&nbsp;$str = &#60;&#60;&#60;EOD
  3&nbsp;Example of string
  4&nbsp;spanning multiple lines
  5&nbsp;using heredoc syntax.
  6&nbsp;EOD;
  7&nbsp;     </PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
   </P
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Note: </B
>
     Here doc support was added in PHP 4.
    </P
></BLOCKQUOTE
></DIV
><P
>&#13;    Strings may be concatenated using the '.' (dot) operator. Note
    that the '+' (addition) operator will not work for this. Please
    see <A
HREF="language.operators.string.html"
>String
    operators</A
> for more information.
   </P
><P
>&#13;    Characters within strings may be accessed by treating the string
    as a numerically-indexed array of characters, using C-like
    syntax. See below for examples.
   </P
><P
>&#13;    <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><P
><B
>Example 6-2. Some string examples</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="programlisting"
>  1&nbsp;
  2&nbsp;&#60;?php
  3&nbsp;/* Assigning a string. */
  4&nbsp;$str = "This is a string";
  5&nbsp;
  6&nbsp;/* Appending to it. */
  7&nbsp;$str = $str . " with some more text";
  8&nbsp;
  9&nbsp;/* Another way to append, includes an escaped newline. */
 10&nbsp;$str .= " and a newline at the end.\n";
 11&nbsp;
 12&nbsp;/* This string will end up being '&#60;p&#62;Number: 9&#60;/p&#62;' */
 13&nbsp;$num = 9;
 14&nbsp;$str = "&#60;p&#62;Number: $num&#60;/p&#62;";
 15&nbsp;
 16&nbsp;/* This one will be '&#60;p&#62;Number: $num&#60;/p&#62;' */
 17&nbsp;$num = 9;
 18&nbsp;$str = '&#60;p&#62;Number: $num&#60;/p&#62;';
 19&nbsp;
 20&nbsp;/* Get the first character of a string  */
 21&nbsp;$str = 'This is a test.';
 22&nbsp;$first = $str[0];
 23&nbsp;
 24&nbsp;/* Get the last character of a string. */
 25&nbsp;$str = 'This is still a test.';
 26&nbsp;$last = $str[strlen($str)-1];
 27&nbsp;?&#62;	  
 28&nbsp;     </PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
   </P
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="language.types.string.conversion"
>String conversion</A
></H2
><P
>&#13;     When a string is evaluated as a numeric value, the resulting
     value and type are determined as follows.</P
><P
>&#13;     The string will evaluate as a double if it contains any of the
     characters '.', 'e', or 'E'. Otherwise, it will evaluate as an
     integer.</P
><P
>&#13;     The value is given by the initial portion of the string. If the
     string starts with valid numeric data, this will be the value
     used. Otherwise, the value will be 0 (zero). Valid numeric data
     is an optional sign, followed by one or more digits (optionally
     containing a decimal point), followed by an optional
     exponent. The exponent is an 'e' or 'E' followed by one or more
     digits.</P
><P
>&#13;     When the first expression is a string, the type of the variable
     will depend on the second expression.
    </P
><DIV
CLASS="informalexample"
><P
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="programlisting"
>  1&nbsp;
  2&nbsp;$foo = 1 + "10.5";              // $foo is double (11.5)
  3&nbsp;$foo = 1 + "-1.3e3";            // $foo is double (-1299)
  4&nbsp;$foo = 1 + "bob-1.3e3";         // $foo is integer (1)
  5&nbsp;$foo = 1 + "bob3";              // $foo is integer (1)
  6&nbsp;$foo = 1 + "10 Small Pigs";     // $foo is integer (11)
  7&nbsp;$foo = 1 + "10 Little Piggies"; // $foo is integer (11)
  8&nbsp;$foo = "10.0 pigs " + 1;        // $foo is integer (11)
  9&nbsp;$foo = "10.0 pigs " + 1.0;      // $foo is double (11)     
 10&nbsp;     </PRE
></TD
></TR
></TABLE
><P
></P
></DIV
><P
>&#13;     For more information on this conversion, see the Unix manual page
     for strtod(3).
    </P
><P
>&#13;     If you would like to test any of the examples in this section,
     you can cut and paste the examples and insert the following line
     to see for yourself what's going on:
     <DIV
CLASS="informalexample"
><P
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="programlisting"
>  1&nbsp;
  2&nbsp;echo "\$foo==$foo; type is " . gettype( $foo ) . "&#60;br&#62;\n";
  3&nbsp;      </PRE
></TD
></TR
></TABLE
><P
></P
></DIV
>
    </P
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="language.types.double.html"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="manual.html"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="language.types.array.html"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Floating point numbers</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="language.types.html"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Arrays</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>