In general, the dynamic output of HTML content in PHP is achieved through print and ECHO statements, and in practice, both print and ECHO functions are almost identical. It can be said that there is a place to use, and the other can be used. However, there is also a very important difference between the two: in the Echo function, you can output multiple strings at the same time, and in the print function you can only output one string at a time. At the same time, the Echo function does not require parentheses, so the echo function is more like a statement than a function. Echo and print are not functions, but language constructs, so parentheses are not required. the difference between them is:
(1) echo can output multiple strings, like this:
?
If you have to add parentheses, note that echo (' A ', ' B ', ' C ') is wrong and should be written as:
?
It does not behave like a function, so it cannot be used in the context of a function (2) print can only output a string, it can behave like a function, for example, you can use the following:
?
1 |
$ret = print ‘Hello World‘ ; |
All of it can be used in more complex expressions. Plus,Echo's efficiency is relatively fast!
The echo command is the same as the Print command, no difference
The Echo function differs from the print function.
Echo () No return value, same as echo command
Print () has a return value, success, return to 1,false, return 0.
printf () is similar to sprintf (), which is formatted output, but is output to standard output, which is output to a variable
PHP echo/print echo ' $firstname com '; When there are variables, you must use double quotes echo just faster than the print Print_r function