PHP回显语句
在PHP中,获取输出的两个基本结构是echo和print。实际上,echo()不是一个函数,它是一个语言构造,因此,您可以在没有括号的情况下使用它。
显示字符串,带有 echo 的变量
句法
echo (arg1, arg2... )
示例:简单的字符串显示
<?php
echo 'One line simple string.<br />';
echo 'Two line simple string example<br />';
echo 'Tomorrow I \'ll learn PHP global variables.<br />';
echo 'This is a bad command : del c:\\*.* <br />';
?>
上面所有的 echo 命令只是显示相应的字符串,这里我们在每个 echo 语句的末尾使用了一个额外的 html 命令 <br /> 来生成换行符,因为 \n 无法在浏览器中生成换行符。
示例:echo 语句内的变量
<?php
// Variables inside an echo statement.
$abc='We are learning PHP';
$xyz='w3resource.com';
echo "$abc at $xyz <br />";
// Simple variable display
echo $abc;
echo "<br />"; // creating a new line
echo $xyz;
echo "<br />"; // creating a new line
// Displaying arrays
$fruits=array('fruit1'=>'Apple','fruit2'=>'Banana');
echo "Fruits are : {$fruits['fruit1']} and
{$fruits['fruit2']}" ;
?>
输出:
We are learning PHP at w3resource.com
We are learning PHP
w3resource.com
Fruits are : Apple and Banana
PHP echo和HTML段落元素
我们可以使用echo功能显示字符串、变量,另外,我们可以将html命令嵌入到echo命令中。这里我们将各种形式的html段落元素附加到echo中。
例子:
<?php
// simple html statement.
echo 'One line simple string.<br />';
// display strings within paragraph with different color.
echo "<p> <font color=blue>One line simple string in
blue color</font> </p>";
echo "<p> <font color=red>One line simple string in red
color</font> </p>";
echo "<p> <font color=green> One line simple string in
green color</font> </p>";
?>
PHP echo 和带有字体颜色的 html 段落元素示例
<?php
// simple html statement.
echo 'One line simple string.<br />';
// display strings within paragraph with different color.
echo "<p> <font color=blue font face='arial' size='2pt'>One line simple string in blue color, arial font and font size 2pt</font> </p>";
echo "<p> <font color=red font face='verdana' size='5pt'>One line simple string in red color, verdana font and font size 5pt</font> </p>";
echo "<p> <font color=green font face='courier' size='6pt'>One line simple string in green color, courier font and font size 6pt</font> </p>";
?>
PHP echo 和 html 段落元素的字体颜色、大小示例
<?php
echo "<p align='left'> <font color=blue size='6pt'>This is left alignment 6pt</font> </p>";
echo "<p align='center'> <font color=blue size='6pt'>This is center alignment 6pt</font> </p>";
echo "<p align='right'> <font color=blue size='6pt'>This is right alignment 6pt</font> </p>";
?>
PHP echo 和 html 段落元素示例,包含字体颜色、大小和 PHP 变量
<?php
$a=1000;
$b=1200;
$c=1400;
echo "<p> <font color=blue size='4pt'> Salary of Mr. A is :</font> <font color=red size='4pt'>$a{#content}lt;/font></p>";
echo "<p> <font color=blue size='4pt'> Salary of Mr. B is :</font> <font color=red size='4pt'>$b{#content}lt;/font></p>";
echo "<p> <font color=blue size='4pt'> Salary of Mr. C is :</font> <font color=red size='4pt'>$c{#content}lt;/font></p>";
?>
PHP echo 和 HTML 表格元素
我们可以使用 echo 函数显示字符串、变量,此外,我们可以将 html 元素嵌入到 echo 命令中。这里我们将 html 表格元素附加到 echo 中。
例子:
<?php
$a=1000;
$b=1200;
$c=1400;
echo "<table border=1 cellspacing=0 cellpading=0>
<tr> <td><font color=blue>Salary of Mr. A is</td> <td>$a{#content}lt;/font></td></tr>
<tr> <td><font color=blue>Salary of Mr. B is</td> <td>$b{#content}lt;/font></td></tr>
<tr> <td><font color=blue>Salary of Mr. C is</td> <td>$c{#content}lt;/font></td></tr>
</table>";
?>
PHP echo 和 HTML 表格元素、字体颜色和 PHP 变量的示例
<?php
$a=1000;
$b=1200;
$c=1400;
echo "<table style='border: 1px solid red;' cellspacing=0 cellpading=0>
<tr> <td><font color=blue>Salary of Mr. A is</td> <td>$a{#content}lt;/font></td></tr>
<tr> <td><font color=blue>Salary of Mr. B is</td> <td>$b{#content}lt;/font></td></tr>
<tr> <td><font color=blue>Salary of Mr. C is</td> <td>$c{#content}lt;/font></td></tr>
</table>";
?>
PHP echo 和 HTML 表格元素、字体颜色、表格边框和 PHP 变量的示例
<?php
$a=1000;
$b=1200;
$c=1400;
echo "<table border=1 cellspacing=0 cellpading=0>
Monthly Salary Statement </table>";
echo "<table border=1 cellspacing=0 cellpading=0>
<tr> <td><font color=blue>Salary of Mr. A is</td> <td>$a{#content}lt;/font></td></tr>
<tr> <td><font color=blue>Salary of Mr. B is</td> <td>$b{#content}lt;/font></td></tr>
<tr> <td><font color=blue>Salary of Mr. C is</td> <td>$c{#content}lt;/font></td></tr>
</table>";
?>
PHP echo html锚元素
我们可以使用 echo 函数显示字符串、变量,此外,我们可以将 html 元素嵌入到 echo 命令中。这里我们将 html 锚元素附加到 echo 中。
例子:
<?php
echo "<a href=echo-order-list.php>
Click here to see the current month salary
statement.</a>";
?>
PHP echo 和带有字体颜色的 HTML 锚元素示例
<?php
echo "<a href=echo-order-list.php>
<font color=blue size=4pt> Click here to
see the current month salary statement.
</font></a>";
?>
PHP echo 和带有字体颜色、大小的 HTML 锚元素示例
<?php
echo "<a href='echo-order-list.php'
style='color: red; font-size: 10pt'>
Click here to see the current month salary statement.
</a>";
?>
PHP echo 和 HTML header 元素
我们可以使用 echo 函数显示字符串、变量,此外,我们可以将 html 元素嵌入到 echo 命令中。这里我们将 html header 元素附加到 echo 中。
例子 :
<?php
echo "<h1> This is header1 </h1> ";
echo "<h2> This is header2 </h2> ";
echo "<h3> This is header3 </h2> ";
echo "<h4> This is header4 </h2> ";
echo "<h5> This is header5 </h2> ";
echo "<h6> This is header6 </h2> ";
?>
PHP echo 和 HTML 标头元素和变量的示例
<?php
$a=1000;
$b=1200;
$c=1400;
echo "<h1> Salary of Mr. A is : $a$ </h1>";
echo "<h2> Salary of Mr. B is : $b$ </h2>";
echo "<h3> Salary of Mr. C is : $c$ </h3>";
?>
PHP echo和HTML列表元素
我们可以使用 echo 函数显示字符串、变量,此外,我们可以将 html 元素嵌入到 echo 命令中。这里我们将 html 有序和无序列表元素附加到 echo 中。
PHP echo 和 HTML 有序列表的示例
<?php
$a=1000;
$b=1200;
$c=1400;
echo "<ol align='left'> <font color=red size='4pt'> Salary statement for the Current month</font><li> <font color=blue>Salary of Mr. A is : $a{#content}lt;/font></li>
<li> <font color=blue>Salary of Mr. B is : $b{#content}lt;/font></li><li> <font color=blue>Salary of Mr. C is : $c{#content}lt;/font></li>
</ol>";
?>
PHP echo 和 HTML 无序列表示例
<?php
$a=1000;
$b=1200;
$c=1400;
echo "<ul align='left'> <font color=red
size='4pt'> Salary statement for the Current month
</font> <li> <font color=blue>Salary of Mr. A is :
$a{#content}lt;/font></li>
<li> <font color=blue>Salary of Mr. B is :
$b{#content}lt;/font></li>
<li> <font color=blue>Salary of Mr. C is :
$c{#content}lt;/font></li>
</ul>";
?>
版权所属:SO JSON在线解析
原文地址:https://www.sojson.com/blog/521.html
转载时必须以链接形式注明原始出处及本声明。
如果本文对你有帮助,那么请你赞助我,让我更有激情的写下去,帮助更多的人。