mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00

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
124 lines
3.5 KiB
Text
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. <? echo ("this is the simplest, an SGML processing instruction\n"); ?>
|
|
|
|
2. <?php echo("if you want to serve XML documents, do like this\n"); ?>
|
|
|
|
3. <script language="php">
|
|
echo ("some editors (like FrontPage) don't
|
|
like processing instructions");
|
|
</script>
|
|
|
|
4. <% echo ("You may optionally use ASP-style tags"); %>
|
|
<%= $variable; # This is a shortcut for "<%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 (?>) also implies the end of the statement, so the
|
|
following are equivalent:
|
|
|
|
<informalexample>
|
|
<programlisting>
|
|
<?php
|
|
echo "This is a test";
|
|
?>
|
|
|
|
<?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>
|
|
<?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>
|
|
<h1>This is an <?# echo "simple";?> example.</h1>
|
|
<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>
|
|
<?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:
|
|
-->
|