Sophie

Sophie

distrib > PLD > ac > amd64 > media > dist > by-pkgid > dd8ef74e7a184506d40e4328053fb785 > files > 3696

php-manual-ro-20051028-1.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML
><HEAD
><TITLE
>Basic syntax</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="Manual PHP"
HREF="index.html"><LINK
REL="UP"
TITLE="Documentaþia limbajului"
HREF="langref.html"><LINK
REL="PREVIOUS"
TITLE="Documentaþia limbajului"
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-2"></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"
>Manual PHP</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="langref.html"
ACCESSKEY="P"
>Înapoi</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"
>Înainte</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="chapter"
><H1
><A
NAME="language.basic-syntax"
>Cap. 5. Basic syntax</A
></H1
><DIV
CLASS="TOC"
><DL
><DT
><B
>Cuprins</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"
>Escaping from HTML</A
></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="AEN526"
></A
><P
><B
>Exemplu 5-1. Ways of escaping from HTML</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
1.&nbsp;&nbsp;<font color="#0000BB">&lt;?php </font><font color="#007700">echo(</font><font color="#DD0000">"if you want to serve XHTML or XML documents, do like this\n"</font><font color="#007700">); </font><font color="#0000BB">?&gt;<br /></font><br />2.&nbsp;&nbsp;<font color="#0000BB">&lt;? </font><font color="#007700">echo (</font><font color="#DD0000">"this is the simplest, an SGML processing instruction\n"</font><font color="#007700">); </font><font color="#0000BB">?&gt;<br /></font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000BB">&lt;?= expression ?&gt;</font> This is a shortcut for "<font color="#0000BB">&lt;? </font><font color="#007700">echo </font><font color="#0000BB">expression ?&gt;</font>"<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />3.&nbsp;&nbsp;<font color="#0000BB">&lt;script language="php"&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">echo (</font><font color="#DD0000">"some editors (like FrontPage) don't<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;like processing instructions"</font><font color="#007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">&lt;/script&gt;<br /></font><br />4.&nbsp;&nbsp;&lt;% echo ("You may optionally use ASP-style tags"); %&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;%= $variable; # This is a shortcut for "&lt;% echo . . ." %&gt;</font>
</code></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="ini.sect.language-options.html#ini.short-open-tag"
>short_open_tag</A
>
    configuration setting in the PHP config file, or by compiling PHP
    with the <VAR
CLASS="option"
>--enable-short-tags</VAR
> option to
    <B
CLASS="command"
>configure</B
>. Even if it is enabled by default in
    <TT
CLASS="filename"
>php.ini-dist</TT
>, use of short tags are discouraged.
   </P
><P
>&#13;    The third way is always available and safe like the first one. However,
    the first is the preferred and most used one.
   </P
><P
>&#13;    The fourth way is only available if <SPAN
CLASS="productname"
>ASP</SPAN
> 
    tags have been enabled using the <A
HREF="ini.sect.language-options.html#ini.asp-tags"
>asp_tags</A
>
    configuration setting.
    <DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Not&#227;: </B
>Support for <SPAN
CLASS="productname"
>ASP</SPAN
> tags was added in 3.0.4.</P
></BLOCKQUOTE
></DIV
>
   </P
><P
>&#13;    <DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Not&#227;: </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
><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.
    Closing tag of a PHP block at the end of a file is optional.
   </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="AEN548"
></A
><P
><B
>Exemplu 5-2. Advanced escaping</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br /></font><font color="#007700">if (</font><font color="#0000BB">$expression</font><font color="#007700">) { <br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">?&gt;<br /></font>&nbsp;&nbsp;&nbsp;&nbsp;&lt;strong&gt;This is true.&lt;/strong&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000BB">&lt;?php <br /></font><font color="#007700">} else { <br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">?&gt;<br /></font>&nbsp;&nbsp;&nbsp;&nbsp;&lt;strong&gt;This is false.&lt;/strong&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000BB">&lt;?php <br /></font><font color="#007700">}<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></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"
>Înapoi</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Acas&#227;</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="language.basic-syntax.instruction-separation.html"
ACCESSKEY="N"
>Înainte</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Documentaþia limbajului</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="langref.html"
ACCESSKEY="U"
>Sus</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Instruction separation</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>