PHP echo command is similar to print command. Echo is a language construct that allows us to print / output some data.
PHP echo commands must end with a semicolon (;)
- This tells PHP that the line terminates here.
- Missing semicolon will produce some error.
Another thing to notice about echo command is that the data to be output should be within double quotation mark or single quotation mark.
Let’s see some basic examples of PHP echo command.
Example one: We can use double quotation mark or single quotation mark to output some data.
<?php echo "Welcome to 9zap.com"; ?>
OR
<?php echo 'Welcome to 9zap.com'; ?>
Example Two: We can also add HTML tags within echo command. Let’s output a bold string / text.
<?php echo "<strong>Welcome to 9zap.com</strong>"; ?>
We can also print a variable value using echo command.
<?php $welcome = "welcome to 9zap.com"; echo $welcome; ?>