Sophie

Sophie

distrib > Mandriva > 9.1 > ppc > media > main > by-pkgid > 0afeee9cca140e167a996902b9a677c5 > files > 2974

php-manual-en-4.3.0-2mdk.noarch.rpm

<HTML
><HEAD
><TITLE
>Basic syntax</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="PHP Manual"
HREF="index.html"><LINK
REL="UP"
TITLE="Language Reference"
HREF="langref.html"><LINK
REL="PREVIOUS"
TITLE="Language Reference"
HREF="langref.html"><LINK
REL="NEXT"
TITLE="Instruction separation"
HREF="language.basic-syntax.instruction-separation.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=ISO-8859-1"></HEAD
><BODY
CLASS="chapter"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation 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="langref.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="language.basic-syntax.instruction-separation.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="chapter"
><H1
><A
NAME="language.basic-syntax"
>Chapter 6. Basic syntax</A
></H1
><DIV
CLASS="TOC"
><DL
><DT
><B
>Table of Contents</B
></DT
><DT
><A
HREF="language.basic-syntax.html#language.basic-syntax.phpmode"
>Escaping from HTML</A
></DT
><DT
><A
HREF="language.basic-syntax.instruction-separation.html"
>Instruction separation</A
></DT
><DT
><A
HREF="language.basic-syntax.comments.html"
>Comments</A
></DT
></DL
></DIV
><DIV
CLASS="sect1"
><H1
CLASS="sect1"
><A
NAME="language.basic-syntax.phpmode"
></A
>Escaping from HTML</H1
><P
>&#13;    When PHP parses a file, it simply passes the text of the file
    through until it encounters one of the special tags which tell it
    to start interpreting the text as PHP code. The parser then
    executes all the code it finds, up until it runs into a PHP
    closing tag, which tells the parser to just start passing the text
    through again. This is the mechanism which allows you to embed PHP
    code inside HTML: everything outside the PHP tags is left utterly
    alone, while everything inside is parsed as code.
   </P
><P
>&#13;    There are four sets of tags which can be used to denote blocks of
    PHP code. Of these, only two (&#60;?php. . .?&#62; and &#60;script
    language="php"&#62;. . .&#60;/script&#62;) are always available; the
    others can be turned on or off from the
    <TT
CLASS="filename"
>php.ini</TT
> configuration file. While the
    short-form tags and ASP-style tags may be convenient, they are not
    as portable as the longer versions. Also, if you intend to embed
    PHP code in XML or XHTML, you will need to use the
    &#60;?php. . .?&#62; form to conform to the XML.
   </P
><P
>&#13;    The tags supported by PHP are:
   </P
><P
>&#13;     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN3123"
></A
><P
><B
>Example 6-1. Ways of escaping from HTML</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>1.  &#60;?php echo("if you want to serve XHTML or XML documents, do like this\n"); ?&#62;

2.  &#60;? echo ("this is the simplest, an SGML processing instruction\n"); ?&#62;
    &#60;?= expression ?&#62; This is a shortcut for "&#60;? echo expression ?&#62;"
    
3.  &#60;script language="php"&#62;
        echo ("some editors (like FrontPage) don't
              like processing instructions");
    &#60;/script&#62;

4.  &#60;% echo ("You may optionally use ASP-style tags"); %&#62;
    &#60;%= $variable; # This is a shortcut for "&#60;% echo . . ." %&#62;</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
    </P
><P
>&#13;    The first way, &#60;?php. . .?&#62;, is the preferred method, as it
    allows the use of PHP in XML-conformant code such as XHTML.
   </P
><P
>&#13;    The second way is not available always. Short tags are available
    only when they have been enabled. This can be done via the
    <B
CLASS="function"
>short_tags()</B
> function (PHP 3 only), by enabling
    the <A
HREF="configuration.directives.html#ini.short-open-tag"
>short_open_tag</A
>
    configuration setting in the PHP config file, or by compiling PHP
    with the --enable-short-tags option to
    <B
CLASS="command"
>configure</B
>. Even if it is enabled by default in
    php.ini-dist, use of short tags are discouraged.
   </P
><P
>&#13;    The fourth way is only available if ASP-style tags have been
    enabled using the <A
HREF="configuration.directives.html#ini.asp-tags"
>asp_tags</A
>
    configuration setting.

    <DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Note: </B
>Support for ASP-style tags was added in 3.0.4.</P
></BLOCKQUOTE
></DIV
>
   </P
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Note: </B
>
     Using short tags should be avoided when developing applications
     or libraries that are meant for redistribution, or deployment on
     PHP servers which are not under your control, because short tags
     may not be supported on the target server.  For portable,
     redistributable code, be sure not to use short tags.
    </P
></BLOCKQUOTE
></DIV
><P
>&#13;    The closing tag for the block will include the immediately
    trailing newline if one is present. Also, the closing tag
    automatically implies a semicolon; you do not need to have a
    semicolon terminating the last line of a PHP block.
   </P
><P
>&#13;    PHP allows you to use structures like this:
    <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN3139"
></A
><P
><B
>Example 6-2. Advanced escaping</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>&#60;?php
if ($expression) { 
    ?&#62;
    &#60;strong&#62;This is true.&#60;/strong&#62;
    &#60;?php 
} else { 
    ?&#62;
    &#60;strong&#62;This is false.&#60;/strong&#62;
    &#60;?php 
}
?&#62;</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
    This works as expected, because when PHP hits the ?&#62; closing
    tags, it simply starts outputting whatever it finds until it hits
    another opening tag. The example given here is contrived, of
    course, but for outputting large blocks of text, dropping out of
    PHP parsing mode is generally more efficient than sending all of
    the text through <A
HREF="function.echo.html"
><B
CLASS="function"
>echo()</B
></A
> or
    <A
HREF="function.print.html"
><B
CLASS="function"
>print()</B
></A
> or somesuch.
   </P
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="langref.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="language.basic-syntax.instruction-separation.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Language Reference</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="langref.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Instruction separation</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>