您的位置:首页 > 编程语言 > PHP开发

php print 函数

2016-05-04 09:04 323 查看
还有一个重要的函数就是exit 函数,该函数类似echo,只是使用该函数输

出内容之后,会终止后面代码的执行,在很多时候,该函数非常有用。exit 函

数还有一个别名就是die 函数。

2.print 函数

另外一个常用的输出函数名为print,其声明格式如下所示:

int print ( string arg )

该函数总是返回1。严格来说print 也不是一个函数,而是一个语法结构,因此输出的时

候,参数不需要括号。

实例2-57 print 语句的应用

本实例演示print 语句的应用,其用法同echo 类似

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

 <head>

  <title> print.php </title>

  <meta charset="UTF-8">

  <meta name="Author" content="">

  <meta name="Keywords" content="">

  <meta name="Description" content="">

 </head>

 <body>

<?php

//直接输出字符串

print("Hello World");

print "<br>";

//可以分成多行写字符串

print "i

want to

fly high";

print "<br>";

//输出引号

print "这一句输出引号 \"我在引号中\".";

// 字符串中包含变量

$foo = "foobar";

$bar = "barbaz";

print "<br>";

print "foo is $foo"; // foo is foobar

print "<br>";

$variable="test_variable";

//输出一段文字

print <<<END

This uses the "here document" syntax to output

multiple lines with $variable interpolation. Note

that the here document terminator must appear on a

line with just a semicolon no extra whitespace!

END;

?>

 </body>

</html>

Hello World

i want to fly high

这一句输出引号 "我在引号中".

foo is foobar

This uses the "here document" syntax to outputmultiple lines with test_variable interpolation. Note that the here document terminator must appear on a line with just a semicolon no extra whitespace!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: