13518219792

建站动态

根据您的个性需求进行定制 先人一步 抢占小程序红利时代

php两种基本的输出方法是什么

本教程操作环境:windows7系统、php7.1版、DELL G3电脑

在 PHP 中,有两种基本的输出方法:echoprint

echo 和 print 之间的差异

提示:echo 比 print 稍快,因为它不返回任何值。

1.echo 是一个语言结构,有无括号均可使用:echo 或 echo();

2.显示字符串,下面的例子展示如何用 echo 命令来显示不同的字符串(同时请注意字符串中能包含 HTML 标记)

PHP is fun!";
echo(123);
echo "
"; echo("我爱php"); echo "
"; echo "Hello world!
"; echo "I'm about to learn PHP!
"; echo "This", " string", " was", " made", " with multiple parameters."; ?>

效果:

PHP is fun!
123
我爱php
Hello world!
I'm about to learn PHP!
This string was made with multiple parameters.

3.显示变量,下面的例子展示如何用 echo 命令来显示字符串和变量;

";
echo "Study PHP at $txt2 
"; echo "My car is a {$cars[0]}"; ?>

效果:

Learn PHP
Study PHP at W3School.com.cn 
My car is a Volvo

PHP print 语句

1、print 也是语言结构,有无括号均可使用:print 或 print()。

2、显示字符串,下面的例子展示如何用 print 命令来显示不同的字符串(同时请注意字符串中能包含 HTML 标记):

PHP is fun!";
print "Hello world!
"; print "I'm about to learn PHP!"; ?>

效果:

PHP is fun!
Hello world!
I'm about to learn PHP!

3.显示变量,下面的例子展示如何用 print 命令来显示字符串和变量:

";
print "Study PHP at $txt2 
"; print "My car is a {$cars[0]}"; ?>

效果:

Learn PHP
Study PHP at W3School.com.cn 
My car is a Volvo

本文名称:php两种基本的输出方法是什么
本文路径:http://cdbrznjsb.com/article/cciiicg.html

其他资讯

让你的专属顾问为你服务