PHP echo() 函數
PHP echo() 函數是一個重要的字符串函數。愛掏網 - it200.com它用于顯示一個或多個字符串。愛掏網 - it200.com換句話說,我們可以說 echo() 函數輸出一個或多個字符串。愛掏網 - it200.com
注意:echo() 函數比 print() 函數稍快。愛掏網 - it200.com
void echo ( string arg1 [, string... ] )
參數 | 描述 | 必填/可選 |
---|---|---|
strings | 指定一個或多個字符串 | 必填 |
示例1
<?php
str ="Hello JavaTpoint";
echo "By using 'echo()' function your string is :".str;
?>
輸出:
By using 'echo()' function your string is :Hello JavaTpoint
示例2
<?php
str1 ="Hello JAVA";str2 ="Hello JavaTpoint";
echo "By using 'echo()' function your string is :".str1."<br>".str2 ;
?>
輸出:
By using 'echo()' function your string is :Hello JAVA
Hello JavaTpoint
示例3
<!DOCTYPE html>
<html>
<head>
<title>PHP 'echo()' function </title>
</head>
<body>
<?php
str ="Red";
?>
<p>Your Shirt color is : <?=str?></p>
</body>
</html>
輸出:
Your Shirt color is : Red
注意:只有在啟用了short_open_tag配置設置的情況下,快捷語法才有效。愛掏網 - it200.com
示例4
<?php
echo "Your number value is: (1 + 2)"."<br>";
echo "By using 'echo()' function: Addition value is: ".(1 + 2)."<br>";
?>
輸出:
Your number value is: (1 + 2)
By using 'echo()' function: Addition value is: 3
示例5
<?php
echo 'Hello ' . (isset(name) ?name : 'John Doe') . '!';
?>
輸出:
Hello John Doe!
示例6
<?php
echo "Your string is : 'This ','string ','was ','made ','with multiple parameters.'"."<br>";
echo 'This ','string ','was ','made ','with multiple parameters.';
?>
輸出:
Your string is : 'This ','string ','was ','made ','with multiple parameters.'
This string was made with multiple parameters.
示例7
<?php
age=array("John"=>"35");
echo "John is " .age['John'] . " years old.";
?>
輸出:
Peter is 35 years old.
聲明:所有內容來自互聯網搜索結果,不保證100%準確性,僅供參考。如若本站內容侵犯了原著者的合法權益,可聯系我們進行處理。