PHP echo is not a function rather it is a language construct. You can use PHP echo when you want to output one or more string. As it is not a function you don’t need to use the parenthesis with it but if you want to pass one or more arguments or parameters, you can use parenthesis with it.
PHP Echo Syntax
1 2 3 |
<?php echo "put your string here"; ?> |
You can use PHP echo statement to print a string, multiline string, variables values, numbers, an array, etc.
Print String Using The PHP echo Statement
PHP echo statement can be used to print the string. You can display a string of text by using echo statement of PHP. You just need to put the string inside the echo statement. For doing this, you need the write the echo and put a single space and then after you can enter your string characters inside the double quotes. Check out below example to see how you can do so.
1 2 3 |
<?php echo "This is the string to print."; ?> |
Output
How to Print Multiline String Using PHP Echo Statement
You can also print the multiline string using the echo statement. PHP remove the spaces automatically when printing the string. If you put one space among string words, PHP will remove those spaces. Let us see it with the example given below-
1 2 3 |
<?php echo "This is my multiline text which you can use to display and print the words that in complete writeup create a sentence."; ?> |
Output
Display HTML Codes Using The Echo Statement
You can print content using HTML codes inside the echo statement. Suppose you want to display paragraph using the echo statement, use the HTML paragraph tag inside the echo statement as given below-
1 2 3 |
<?php echo "<p>This is the paragraph to display using the echo statement</p>"; ?> |
Output
Output Variables Using The Echo Statement
You can print content using HTML codes inside the echo statement. Suppose you want to display paragraph using the echo statement, use the HTML paragraph tag inside the echo statement as given below-
1 2 3 4 5 6 |
<?php $myvar = 20; $radar = 50; $result = $myvar + $radar; echo "This is the final result:".$result; ?> |
Output
You must also read:-
Reference:-