PHP echo is a function used to output data. Its syntax is echo (string | variable). It will append the value of the specified string or variable to the end of the output buffer. echo can be used to directly output strings, variable values, multiple values, and HTML markup. The data it outputs will be automatically converted to a string, and the output will be immediately sent to the output buffer.
Usage of echo in PHP
echo is a built-in function in PHP for outputting data. It appends the specified string or variable value to the end of the output buffer.
Syntax:
<code class="php">echo (string | variable);</code>
Parameters:
Usage:
Output the string directly:
<code class="php">echo "Hello World!";</code>
Output the value of the variable:
<code class="php">$name = "John Doe"; echo $name;</code>
Output multiple values at the same time:
Multiple values can be separated by commas , output in sequence.
<code class="php">echo "Name: ", $name, ", Age: ", $age;</code>
Use HTML tags:
HTML tags can be output in echo.
<code class="php">echo "<p>This is a paragraph.</p>";</code>
Note:
var_dump()
or print_r()
function. ob_start()
and ob_get_clean()
functions. The above is the detailed content of How to use echo in php. For more information, please follow other related articles on the PHP Chinese website!