PHP函数echo()的定义和用法解析_PHP教程

php中文网
发布: 2016-07-15 13:30:10
原创
1312人浏览过

在使用定义和用法

PHP函数echo()输出一个或多个字符串。

语法

echo(strings)

参数 描述

立即学习PHP免费学习笔记(深入)”;

strings 必需。一个或多个要发送到输出的字符串。

提示和注释

通义听悟
通义听悟

阿里云通义听悟是聚焦音视频内容的工作学习AI助手,依托大模型,帮助用户记录、整理和分析音视频内容,体验用大模型做音视频笔记、整理会议记录。

通义听悟 85
查看详情 通义听悟

注释:echo() 实际上不是一个函数,因此您无需对其使用括号。不过,如果您希望向 echo() 传递一个或多个参数,那么使用括号会发生解析错误。

提示:echo() 函数比 print() 函数快一点点。

提示:PHP函数echo()可以使用简化语法。参见以下示例。

<OL class=dp-xml><LI class=alt><SPAN><SPAN class=tag><</SPAN><SPAN class=tag-name>html</SPAN><SPAN class=tag>></SPAN><SPAN> </SPAN><SPAN class=tag><</SPAN><SPAN class=tag-name>body</SPAN><SPAN class=tag>></SPAN><SPAN> </SPAN></SPAN><LI class=alt><SPAN><SPAN><?</SPAN><SPAN class=tag><?</span><SPAN class=tag-name>php</SPAN><SPAN> $</SPAN><SPAN class=attribute>color</SPAN><SPAN> = </SPAN><SPAN class=attribute-value>"red"</SPAN><SPAN>; </SPAN><SPAN class=tag>?></SPAN></SPAN></SPAN><LI class=alt><SPAN><SPAN class=tag><SPAN class=tag></SPAN><SPAN> </SPAN><SPAN class=tag><</SPAN><SPAN class=tag-name>p</SPAN><SPAN class=tag>></SPAN><SPAN>Roses are </SPAN></SPAN></SPAN><LI class=alt><SPAN><SPAN class=tag><SPAN><?</SPAN><SPAN class=tag><?</span><SPAN>=$color</SPAN><SPAN class=tag>?></SPAN></SPAN></SPAN></SPAN><LI class=alt><SPAN><SPAN class=tag><SPAN class=tag><SPAN class=tag></< SPAN><SPAN class=tag></< span><SPAN class=tag-name>p</SPAN><SPAN class=tag>></SPAN></SPAN></SPAN></SPAN></SPAN><LI class=alt><SPAN><SPAN class=tag><SPAN class=tag><SPAN class=tag><SPAN class=tag></SPAN><SPAN> </< SPAN><SPAN class=tag></< span><SPAN class=tag-name>body</SPAN><SPAN class=tag>></SPAN><SPAN> </SPAN></SPAN></SPAN></SPAN></SPAN></SPAN><LI class=alt><SPAN><SPAN class=tag><SPAN class=tag><SPAN class=tag><SPAN class=tag><SPAN></< SPAN><SPAN class=tag></< span><SPAN class=tag-name>html</SPAN><SPAN class=tag>></SPAN><SPAN> </SPAN></SPAN></LI></OL>
登录后复制

 1.echo 输出标量

<OL class=dp-xml><LI class=alt><SPAN><SPAN class=tag><?</span><SPAN class=tag-name>php</SPAN><SPAN> </SPAN></SPAN><LI><SPAN>  echo 123adb; //输出正确  </SPAN><LI class=alt><SPAN>  echo 123abd; //正确  </SPAN><LI><SPAN>  echo "123adb"; //正确  </SPAN><LI class=alt><SPAN class=tag>?></SPAN><SPAN> </SPAN></LI></OL>
登录后复制

2、PHP函数echo()输出变量,常量

<OL class=dp-xml><LI class=alt><SPAN><SPAN class=tag><?</span><SPAN class=tag-name>php</SPAN><SPAN> </SPAN></SPAN><LI><SPAN>$</SPAN><SPAN class=attribute>a</SPAN><SPAN>=</SPAN><SPAN class=attribute-value>"123456"</SPAN><SPAN>;  </SPAN><LI class=alt><SPAN>echo $a;  //正确  </SPAN><LI><SPAN>echo "</SPAN><SPAN class=tag></< span><SPAN class=tag-name>br</SPAN><SPAN class=tag>></SPAN><SPAN>";  </SPAN><LI class=alt><SPAN>echo "$a"; //正确  </SPAN><LI><SPAN>echo "</SPAN><SPAN class=tag></< span><SPAN class=tag-name>br</SPAN><SPAN class=tag>></SPAN><SPAN>";  </SPAN><LI class=alt><SPAN>echo $a;//不正确  </SPAN><LI><SPAN>echo "</SPAN><SPAN class=tag></< span><SPAN class=tag-name>br</SPAN><SPAN class=tag>></SPAN><SPAN>";  </SPAN><LI class=alt><SPAN>echo abcdef;  //也能正确的显示,但是强烈不建议这么做,<br>因为有很多特殊符号这么做不能正确的显示。  </SPAN><LI><SPAN>echo "</SPAN><SPAN class=tag></< span><SPAN class=tag-name>br</SPAN><SPAN class=tag>></SPAN><SPAN>";  </SPAN><LI class=alt><SPAN>//echo </SPAN><SPAN class=tag><</SPAN><SPAN class=tag-name>abd</SPAN><SPAN class=tag>></SPAN><SPAN>;  //比如说这样,带了尖括的,就不能用,<br>你可以去了前面的注释试试会不会报错。  </SPAN><LI><SPAN>echo "</SPAN><SPAN class=tag></< span><SPAN class=tag-name>br</SPAN><SPAN class=tag>></SPAN><SPAN>";  </SPAN><LI class=alt><SPAN>$</SPAN><SPAN class=attribute>b</SPAN><SPAN>=</SPAN><SPAN class=attribute-value>10</SPAN><SPAN>;  </SPAN><LI><SPAN>echo $b+10; //显示 20  </SPAN><LI class=alt><SPAN>echo "</SPAN><SPAN class=tag></< span><SPAN class=tag-name>br</SPAN><SPAN class=tag>></SPAN><SPAN>";  </SPAN><LI><SPAN>echo "$b+10";  </SPAN><LI class=alt><SPAN>echo "</SPAN><SPAN class=tag></< span><SPAN class=tag-name>br</SPAN><SPAN class=tag>></SPAN><SPAN>";  </SPAN><LI><SPAN>echo "结果是:"."$b"; //这两种写法的效果是一样的。  </SPAN><LI class=alt><SPAN>echo "</SPAN><SPAN class=tag></< span><SPAN class=tag-name>br</SPAN><SPAN class=tag>></SPAN><SPAN>";  </SPAN><LI><SPAN>echo "结果是:$b";  //这两种写法的效果是一样的。  </SPAN><LI class=alt><SPAN class=tag>?></SPAN><SPAN> </SPAN></LI></OL>
登录后复制

echo ""和PHP函数echo()是有区别的,加双引号时会对变量与特定的符号进行转义,加单引号时不会进行转义,会将单引号内的符号直接的输出,所以说用单引号比用双引号时更快一点。能不用双引号时就不要用了吧。


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/446316.htmlTechArticle在使用 定义和用法 PHP函数echo()输出一个或多个字符串。 语法 echo(strings) 参数 描述 strings 必需。一个或多个要发送到输出的字符串。 提示...
相关标签:
php
PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号