mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-17 01:18:55 +00:00

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@55884 c90b9560-bf6c-de11-be94-00142212c4b1
212 lines
6.4 KiB
XML
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. <? echo ("this is the simplest, an SGML processing instruction\n"); ?>
|
|
<?= expression ?> This is a shortcut for "<? echo expression ?>"
|
|
|
|
2. <?php echo("if you want to serve XHTML or 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>
|
|
|
|
<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">
|
|
<?php
|
|
|
|
if (boolean-expression) {
|
|
?>
|
|
<strong>This is true.</strong>
|
|
<?php
|
|
} else {
|
|
?>
|
|
<strong>This is false.</strong>
|
|
<?php
|
|
}
|
|
?>
|
|
</programlisting></example>
|
|
|
|
This works as expected, because PHP handles text within ?> and
|
|
<?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 (?>) 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></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>
|
|
<?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>
|
|
<h1>This is an <?php # 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.</simpara>
|
|
|
|
<informalexample><programlisting>
|
|
<?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:
|
|
-->
|