php-doc-en/language/basic-syntax.sgml
James Gingerich e1be327855 Whee. Now the language stuff is broken back up into a bunch of seperate
files again. (Only this time, the way it is divided up makes a bit of
sense.)


git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@9863 c90b9560-bf6c-de11-be94-00142212c4b1
1999-06-20 02:25:34 +00:00

124 lines
3.5 KiB
Text

<chapter id="language.basic-syntax">
<title>Basic syntax</title>
<sect1 id="language.basic-syntax.phpmode">
<title>Escaping from HTML</title>
<para>
There are four ways of escaping from HTML and entering "PHP code
mode":
<para>
<example>
<title>Ways of escaping from HTML</title>
<programlisting>
1. &lt;? echo ("this is the simplest, an SGML processing instruction\n"); ?>
2. &lt;?php echo("if you want to serve XML documents, do like this\n"); ?>
3. &lt;script language="php">
echo ("some editors (like FrontPage) don't
like processing instructions");
&lt;/script>
4. &lt;% echo ("You may optionally use ASP-style tags"); %>
&lt;%= $variable; # This is a shortcut for "&lt;%echo .." %>
</programlisting>
</example>
<para>
The first way is only available if short tags have been enabled
(either by calling <function>short_tags</function>, they are
configured on using the short_tags run-time configuration setting,
or they are enabled using the --enable-short-tags compile-time
configuration setting.
<para>
The fourth way is only available if ASP-style tags have been
enabled using either the asp_tags configuration setting or the
--enable-asp-tags compile-time configuration setting.
<note>
<para>Support for ASP-style tags was added in 3.0.4.</para>
</note>
<para>
The closing "bracket" for the block will include the immediately
trailing newline if one is present.
<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.
<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>
<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>
<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.
<informalexample><programlisting>
&lt;h1>This is an &lt;?# 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.
<informalexample><programlisting>
&lt;?php
/*
echo "This is a test"; /* This comment will cause a problem */
*/
?>
</programlisting></informalexample>
</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:
-->