mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 17:08:54 +00:00
Adding more echo examples per errata.
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@44014 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
a8da862ae2
commit
c637fc0e66
1 changed files with 36 additions and 8 deletions
|
@ -489,10 +489,12 @@ $new_string = chunk_split (base64_encode($data));
|
|||
<para>
|
||||
<function>Echo</function> is not actually a function (it is a
|
||||
language construct) so you are not required to use parantheses
|
||||
with it.
|
||||
with it. In fact, if you want to pass more than one parameter
|
||||
to echo, you must not enclose the parameters within parentheses.
|
||||
<example>
|
||||
<title><function>Echo</function> example</title>
|
||||
<title><function>Echo</function> examples</title>
|
||||
<programlisting role="php">
|
||||
<?php
|
||||
echo "Hello World";
|
||||
|
||||
echo "This spans
|
||||
|
@ -500,15 +502,41 @@ multiple lines. The newlines will be
|
|||
output as well";
|
||||
|
||||
echo "This spans\nmultiple lines. The newlines will be\noutput as well.";
|
||||
|
||||
echo "escaping characters is done \"Like this\"."
|
||||
|
||||
//You can use variables inside of an echo statement
|
||||
$foo = "foobar";
|
||||
$bar = "barbaz";
|
||||
|
||||
echo "foo is $foo"; // foo is foobar
|
||||
|
||||
// Using single quotes will print the variable name, not the value
|
||||
echo 'foo is $foo'; // foo is $foo
|
||||
|
||||
// If you are not using any other characters, you can just echo variables
|
||||
echo $foo; // foobar
|
||||
echo $foo,$bar; // foobarbarbaz
|
||||
|
||||
// because echo is not a function, following code is invalid.
|
||||
($some_var) ? echo('true'): echo('false');
|
||||
|
||||
// However, the following examples will work:
|
||||
($some_var) ? print('true'): print('false'); // print is a function
|
||||
echo ($some_var) ? 'true': 'false'; // changing the statement around
|
||||
?>
|
||||
</programlisting>
|
||||
</example>
|
||||
</para>
|
||||
<para>
|
||||
<function>Echo</function> also has a shortcut syntax, where you
|
||||
can immediately follow the opening tag with an equals sign.
|
||||
<informalexample>
|
||||
<programlisting role="php">
|
||||
I have <?=$foo?> foo.
|
||||
</programlisting>
|
||||
</informalexample>
|
||||
</para>
|
||||
<note>
|
||||
<para>
|
||||
In fact, if you want to pass more than one parameter to echo,
|
||||
you must not enclose the parameters within parentheses.
|
||||
</para>
|
||||
</note>
|
||||
<simpara>
|
||||
See also:
|
||||
<function>print</function>,
|
||||
|
|
Loading…
Reference in a new issue