PHP Echo
PHP echo is a language construct not a function, so you don’t need to use parenthesis with it. But if you want to use more than one parameters, it is required to use parenthesis.
The syntax of PHP echo is given below:
void echo ( string $arg1[, string $… ] )
PHP echo statement can be used to print string, multi line strings, escaping characters, variable, array etc.
Printing string
<?php echo "Hello World !! "; ?> //Output: Hello World !!
Printing multi line string
<?php echo " PHP echo Multiline Test. "; ?> //Output: PHP echo Multiline Test.
Printing escaping characters
<?php echo "Hello \" World \" "; ?> //Output: Hello " World "
Printing variable value
<?php $msg = "Hello Sam"; echo " Message is :$msg "; ?> //Output: Message is: Hello Sam
PHP Print
PHP print is a language construct, so you don’t need to use parenthesis with the argument list. Unlike echo, it always returns 1.
The syntax of PHP print is given below:
int print(string $arg)
PHP print statement can be used to print string, multi line strings, escaping characters, variable, array etc.
Printing string
<?php print "Hello World !!"; print ("Hello World !!"); ?> //Output: Hello World !! Hello World !!
Printing multi line string
<?php print "Hello World Multi line Test Statement "; ?> //Output:Hello World Multi line Test Statement
Printing escaping characters
<?php print "Hello World \"escaping\" characters Statement"; ?> //Output:Hello World "escaping" characters Statement
Printing variable value
<?php $msg="Hello World print() in PHP"; print "Test Variable : $msg"; ?> //Output: Test Variable : Hello World print() in PHP