CKTIS / PHP
echo: writing text to output
echo sends values to program output. It is a language construct rather than an ordinary function and provides no result to assign.
Version: PHP 8.4
Syntax
echo expression, ...;The statement echo "Total: ", 2 + 3; writes successive expressions without automatic spaces or a newline. Add them explicitly. Commas separate expressions; the . operator joins strings into one expression.
echo does not accept named arguments and cannot be passed as a callback. Do not write $result = echo "ok";: this is invalid syntax. Parentheses may surround one expression, but do not create an ordinary function call with an argument list.
Numbers are converted to text. false produces an empty string and true the string 1, so prefer var_dump when inspecting types and diagnostic values. Do not output arrays as text without choosing an appropriate format.
echo does not make HTML safe. In the example, htmlspecialchars encodes markup as text; UTF-8 and flags for quotes and invalid sequences are explicit. This suits an HTML text context, not universal protection for SQL, JavaScript or URLs.
Examples
<?php
declare(strict_types=1);
echo "Total: ", 2 + 3, "\n";
$name = "<b>Ada</b>";
echo htmlspecialchars($name, ENT_QUOTES | ENT_SUBSTITUTE, "UTF-8"), "\n";
Result
Total: 5 <b>Ada</b>