PHP回显语句

JSON 2024-04-12 16:29:34 202

在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

转载时必须以链接形式注明原始出处及本声明。

本文主题:
php

如果本文对你有帮助,那么请你赞助我,让我更有激情的写下去,帮助更多的人。

关于作者
一个低调而闷骚的男人。
相关文章
PHP if/else/elseif 语句
PHP if/else/elseif 语句
PHP变量剖析
PHP变量剖析
Java API接口返不是JSON的解决方案,SpringMVC返JSON配置。
PHP用户定义函数详细讲解
JQuery Ajax四种写法,Ajax请求返JSON 操作Demo
Elasticsearch 聚合(aggregation)查询返所有
关于一位“caoz的梦呓”的大佬在微信公众号喷我的整体
PHP用户定义函数详细讲解
最新文章
Linux I/O重定向 1768
Ruby 循环 - while、for、until、break、redo 和 retry 711
Node.js:全局对象 517
如何使用终端检查Linux上的内存使用情况 635
JavaScript对象详细剖析 300
Python print() 函数 409
PHP if/else/elseif 语句 407
HTML5 Canvas弧线教程 387
Java赋值运算符 431
XML内部实体和外部实体 464
最热文章
最新MyEclipse8.5注册码,有效期到2020年 (已经更新) 686836
苹果电脑Mac怎么恢复出厂系统?苹果系统怎么重装系统? 675081
免费天气API,天气JSON API,不限次数获取十五天的天气预报 615809
免费天气API,全国天气 JSON API接口,可以获取五天的天气预报 611126
Jackson 时间格式化,时间注解 @JsonFormat 用法、时差问题说明 555627
我为什么要选择RabbitMQ ,RabbitMQ简介,各种MQ选型对比 510028
Elasticsearch教程(四) elasticsearch head 插件安装和使用 481399
Jackson 美化输出JSON,优雅的输出JSON数据,格式化输出JSON数据... ... 269208
Java 信任所有SSL证书,HTTPS请求抛错,忽略证书请求完美解决 244787
Elasticsearch教程(一),全程直播(小白级别) 227490
支付扫码

所有赞助/开支都讲公开明细,用于网站维护:赞助名单查看

查看我的收藏

正在加载... ...