PHP中Echo与Print的区别

2010年02月19日  |  11:42分类:PHP技术  |  标签:  |  1,316 views

在PHP中常用的输出主要由echo和print,还有printf用的比较少一点,其实这几个输出也是有一些区别的,下面简单介绍一下其中的区别。

1.echo:echo可以同时输出多个字符串,并不需要圆括号,echo更像一条语句。

echo()无返回值,与echo命令相同。echo可以有多个参数,无返回值。

2.print:print只可以同时输出一个字符串,需要圆括号。

   print是函数,它的用法个C语言很像,所以会对输出内容里的 %  作特殊解释。

Print还可以这样用:

<?php

print <<<dND

<html xmlns=”http://www.w3.org/1999/xhtml“>

<head>

<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ />

<title>长沙网站设计_长沙网站开发-小龙包</title>

</head>

<body>

<a href=”http://www.shansghayb.com/“>长沙网站设计长沙网站开发</a>

</body>

</html>

dND

?>

这样可以输出大段的HTML,而且不用把里面的引号转义。

print有一个参数,返回值有TRUE,1,false,0;

print()有返回值,当其执行失败的时候(如断线)时返回false;

printf()为格式化输出,sprintf()与之类似,不同的是前者输出到标准输出,后者输出到变量。

原创文章,转载请注明: 转载自长沙营销型网站建设,营销型网站开发,Zen-Cart | 小龙包

本文链接地址: PHP中Echo与Print的区别

喜欢本文,那就收藏到: Del.icio.us Google书签 Digg Live Bookmark Technorati Furl Yahoo书签 Facebook 百度搜藏 新浪ViVi 365Key网摘 天极网摘 和讯网摘 博拉网 POCO网摘 添加到饭否 QQ书签 Digbuzz我挖网

发表您的评论

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word