Output statement of basic PHP development tutorial
Summary:
There are two basic output methods in PHP: echo and print.
In this chapter we will discuss the usage of the two statements in detail and demonstrate how to use echo and print in examples.
1. Two common output statements of PHP
The difference between echo and print:
echo - can output one or more strings
print - only one string is allowed to be output, and the return value is always 1
Note: echo outputs faster than print, echo has no return value, and print has a return value of 1. In most cases, echo is still used for output.
2. PHP echo statement
echo is a language structure, which can be used without parentheses or with parentheses: echo or echo().
Display string
The following example demonstrates how to use the echo command to output characters String (string can contain HTML tags):
php.cn 大家都来进入PHP的世界吧!"; echo "Hello world!
"; echo "我"," 想"," 学习 "," PHP!
"; ?>
Display variable
The following example demonstrates how to use The echo command outputs variables and strings:
php.cn "; echo $b; ?>
3. PHP print statement
print is also a language structure, with or without parentheses: print or print().
Display string
The following example demonstrates how to use the print command to output a string (the string can contain HTML tag):
php.cn 大家都来进入PHP的世界吧!"; print "Hello world!
"; ?>
Display variables
The following example demonstrates how to use the print command to output variables and characters String:
php.cn "; print $b; ?>
Learning experience: Note that echo can output one or more strings, while print can only output one string, and the return value is always 1.