php-doc-en/language/basic-syntax.xml
Derick Rethans 455a83ea33 - Fixed spelling
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@55884 c90b9560-bf6c-de11-be94-00142212c4b1
2001-08-24 10:18:59 +00:00

212 lines
6.4 KiB
XML

<?xml encoding="iso-8859-1"?>
<!-- $Revision: 1.15 $ -->
<chapter id="language.basic-syntax">
<title>Basic syntax</title>
<!--
NOTE: Last modified: 2001-05-16 13:00 GMT
the language part is currently under heavy revision. Please do not
not make any heavy (i.e. structural) modifications to this part
for a moment.
You'd also better not start any translation yet.
Comments are always welcome at phpdoc@lists.php.net
Progress:
intro : DOESN'T EXIST - yet?
new chapter, with some introductionary remarks?
Will be discussed on the ML soon.
basic-syntax:
FINISHED
except maybe moving the 'advanced escaping'
to a better place?
TODO:
- nada
types : Being revised. Added all new types
Boolean and Integer are more or less finished.
The rest isn't.
TODO:
- why is $foo[bar] bad syntax?
- what's the difference between unset($bla) and
$bla = NULL; (it is different!)
- $obj->{expr} syntax
- (unset) cast?????
- $bla = unset <== should've been nuked, don't mention it
- $str{offset} syntax, rather than $str[offset]
- read notes and apply when any of them are useful
- remove notes which have been included here.
- ...
the rest: Not yet started with.
TODO:
- ?
oop : has been revised by Kristian, DONE.
-->
<sect1 id="language.basic-syntax.phpmode">
<title>Escaping from HTML</title>
<para>
When PHP starts to handle file, it will just output the text
it encounters. So if you have a HTML-file, and you change its
extension to .php, your file will keep working.
</para>
<para>
If you want to insert php-statements at some point in your
file, you'll need to indicate so to php, by entering "PHP mode"
in either of the following ways:
</para>
<para>
<example>
<title>Ways of escaping from HTML</title>
<programlisting>
1. &lt;? echo ("this is the simplest, an SGML processing instruction\n"); ?&gt;
&lt;?= expression ?&gt; This is a shortcut for "&lt;? echo expression ?&gt;"
2. &lt;?php echo("if you want to serve XHTML or XML documents, do like this\n"); ?&gt;
3. &lt;script language="php"&gt;
echo ("some editors (like FrontPage) don't
like processing instructions");
&lt;/script&gt;
4. &lt;% echo ("You may optionally use ASP-style tags"); %&gt;
&lt;%= $variable; # This is a shortcut for "&lt;%echo .." %&gt;
</programlisting>
</example>
</para>
<para>
The first way is only available if short tags have been
enabled. This can be done
<!-- via the <function>short_tags</function> function,-->
by enabling the <link linkend="ini.short-open-tag">short_open_tag</link>
configuration setting in the PHP config file, or by compiling PHP with the
--enable-short-tags option to <command>configure</command>.
</para>
<para>
The second way is the generally preferred method, as it allows for the
next generation of XHTML to be easily implemented with PHP.
</para>
<para>
The fourth way is only available if ASP-style tags have been
enabled using the <link linkend="ini.asp-tags">asp_tags</link>
configuration setting.
<note>
<para>Support for ASP-style tags was added in 3.0.4.</para>
</note></para>
<para>
The closing tag for the block will include the immediately
trailing newline if one is present.
</para>
<para> <!-- TODO: find a better place for this para -->
PHP allows you to use structures like this:
<example><title>Advanced escaping</title>
<programlisting role="php">
&lt;?php
if (boolean-expression) {
?&gt;
&lt;strong&gt;This is true.&lt;/strong&gt;
&lt;?php
} else {
?&gt;
&lt;strong&gt;This is false.&lt;/strong&gt;
&lt;?php
}
?&gt;
</programlisting></example>
This works as expected, because PHP handles text within ?&gt; and
&lt;?php as an <function>echo</function> statement.
<!-- without the parsing if vars, that is (hopefully?) obvious -->
</para>
</sect1>
<sect1 id="language.basic-syntax.instruction-separation">
<title>Instruction separation</title>
<simpara>
Instructions are separated the same as in C or perl - terminate
each statement with a semicolon.</simpara>
<para>
The closing tag (?&gt;) also implies the end of the statement, so the
following are equivalent:
<informalexample>
<programlisting>
&lt;?php
echo "This is a test";
?>
&lt;?php echo "This is a test" ?>
</programlisting>
</informalexample></para></sect1>
<sect1 id="language.basic-syntax.comments">
<title>Comments</title>
<para>
PHP supports 'C', 'C++' and Unix shell-style comments. For example:
<informalexample><programlisting>
&lt;?php
echo "This is a test"; // This is a one-line c++ style comment
/* This is a multi line comment
yet another line of comment */
echo "This is yet another test";
echo "One Final Test"; # This is shell-style style comment
?>
</programlisting>
</informalexample></para>
<simpara>
The "one-line" comment styles actually only comment to the
end of the line or the current block of PHP code, whichever
comes first.</simpara>
<informalexample><programlisting>
&lt;h1>This is an &lt;?php # echo "simple";?> example.&lt;/h1>
&lt;p>The header above will say 'This is an example'.
</programlisting></informalexample>
<simpara>
You should be careful not to nest 'C' style comments, which can
happen when commenting out large blocks.</simpara>
<informalexample><programlisting>
&lt;?php
/*
echo "This is a test"; /* This comment will cause a problem */
*/
?>
</programlisting></informalexample></sect1>
</chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->