PHP - echo
Trieda
Metóda - echo
(PHP 4, PHP 5, PHP 7)
echo() prints one or more strings and does not add a new line
after printing. It is not a function, but it is a language construct
(echo can be called without parentheses). We can pass more than one
parameter (actually the number of parameters is not limited) and then they are
printed one by one. However, if we want to use that, we must not call the
function with parentheses.
echo has also shortcut syntax that we can use e.g. for printing
values in templates. However, we must enable short_open_tag for it. The
shortcut syntax looks as follows:
This is only <?= "a sample" ?> code.
Procedurálne
- function echo (string $arg1, string $...) : void
Parametre
| Názov | Dátový typ | Predvolená hodnota | Popis |
|---|---|---|---|
| $arg1 | string | The parameter to output. | |
| $... | string | Additional parameters to output. |
Mávratovej hodnoty
Vracia: void
Returns no value.
Príklady
<?php
echo "echo without parentheses", "<br />";
echo ("echo() with parentheses");
Using the shortcut syntax (do not forget to enable short_open_tag):
<?= "Using the shortcut syntax" ?>
echo ignores a multiline string. However, we can use
\n for a new line:
<?php
echo "Multiline text
is totally
ignored", "<br />";
echo ("Multiline text\nusing special\ncharacters");
Súvisiace manuály
- function printf (string $format, mixed $args, mixed $...) : int
