Home >Backend Development >PHP Tutorial >php: Detailed explanation of echo usage examples
Official manual description:
Definition and Usage
Definition and Usage
The echo() function outputs one or more strings.
echo()The function is used to output one or more strings.
Syntax
Syntax
echo(strings)
Parameter Parameter Description
strings Required. One or more strings to be sent to the output
Required parameters . Specify one or more strings that need to be sent to the results
Tips and Notes
Tips and Notes
Note: The echo() function is not actually a function, so you are not required to use parentheses with it. However, if you want to pass more than one parameter to echo(), using parentheses will generate a parse error.
Note: The echo() function is not a real function, so you don’t have to Go use it. If you want to pass more than one argument to the echo() function, using parentheses "()" will generate an error.
Tip: The echo() function is slightly faster than print().
Tip: The echo() function is equivalent to a simplified version of the print() function.
Tip: The echo() function has the following shortcut syntax. See example 5.
Tip: The echo() function has the following shortcut syntax. For details, see: Case 5.
Example 1
Case 1
<?php $str = "Who's Kai Jim?"; echo $str; echo "<br />"; echo $str."<br />I don't know!"; ?>
The output of the code above will be:
The above code will output the following results:
Who's Kai Jim?Who's Kai Jim?I don 't know!
Case 2
<?php echo "This textspans multiplelines."; ?>
The output of the code above will be:
The above code will output the following result:
This text spans multiple lines.
Case 3
<?php echo 'This ','string ','was ','made ','with multiple parameters'; ?>
The output of the code above will be:
The above code will output the following results:
This string was made with multiple parameters
Case 4
Difference of single and double quotes. Single quotes will print the variable name, not the value:
Difference between single quotes (') and double quotes ("). Single quotes will print Output variable name instead of the value of the variable:
<?php $color = "red"; echo "Roses are $color"; echo "<br />"; echo 'Roses are $color'; ?>
The output of the code above will be:
The above code will output the following results:
Roses are redRoses are $color
Case 5
Shortcut syntax:
Shortcut (shortcut) syntax:
<html> <body> <?php $color = "red"; ?> <p>Roses are <?=$color?></p> </body> </html>
The above is the detailed content of php: Detailed explanation of echo usage examples. For more information, please follow other related articles on the PHP Chinese website!