php: Detailed explanation of echo usage examples

伊谢尔伦
Release: 2023-03-11 10:30:02
Original
2387 people have browsed it

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&#39;s Kai Jim?"; 
echo $str; 
echo "<br />"; 
echo $str."<br />I don&#39;t know!"; 
?>
Copy after login

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."; 
?>
Copy after login

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 &#39;This &#39;,&#39;string &#39;,&#39;was &#39;,&#39;made &#39;,&#39;with multiple parameters&#39;; 
?>
Copy after login

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 &#39;Roses are $color&#39;; 
?>
Copy after login

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>
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!