PHP 5 echo / print statement
There are two basic output in PHP: echo and print.
This chapter we will discuss in detail the use of the two statements, and demonstrates how to use echo and print in the instance.
PHP echo and print statements
echo and print the difference between:
- echo - Output one or more strings can
- print - allows only output a string, the return value is always 1
Tip: print speed faster than output echo, echo does not return a value, print return a value of 1.
PHP echo statement
echo is a language construct, you can not use the time brackets, you can also add parentheses: echo or echo ().
Display string
The following example demonstrates how to use the echo command output string (string may contain HTML tags):
Examples
echo "<h2> PHP is fun </ h2>!";
echo "! Hello world <br>";
echo "I'm about to learn PHP <br>!";
echo "This", "string", "was", "made", "with multiple parameters.";
?>
try it"
Display variable
The following example demonstrates how to use the echo command output variables and strings:
Examples
$ Txt1 = "Learn PHP";
$ Txt2 = "w3cschool.cc";
$ Cars = array ( "Volvo", "BMW", "Toyota");
echo $ txt1;
echo "<br>";
echo "Study PHP at $ txt2";
echo "My car is a {$ cars [0]}";
?>
try it"
PHP print statement
print also is a language construct, you can use parentheses, you can not use parentheses: print or print ().
Display string
The following example demonstrates how to use the print command output string (string may contain HTML tags):
Examples
print "<h2> PHP is fun </ h2>!";
print "! Hello world <br>";
print "I'm about to learn PHP!";
?>
try it"
Display variable
The following example demonstrates how to use the print command output variables and strings:
Examples
$ Txt1 = "Learn PHP";
$ Txt2 = "w3cschool.cc";
$ Cars = array ( "Volvo", "BMW", "Toyota");
print $ txt1;
print "<br>";
print "Study PHP at $ txt2";
print "My car is a {$ cars [0]}";
?>
try it"