PHP print () function
Definition and Usage
print () function outputs one or more strings.
Note: print () function is not actually a function, so you do not have to use it in parentheses.
Tip: print () function than echo () at a slower pace.
grammar
print( strings )
参数 | 描述 |
---|---|
strings | 必需。发送到输出的一个或多个字符串。 |
technical details
return value: | Always returns 1. |
---|---|
PHP version: | 4+ |
More examples
Example 1
Output string variable ($ str) values:
<?php
$str = "Hello world!";
print $str;
?>
$str = "Hello world!";
print $str;
?>
Running instance »
Example 2
Output string variable ($ str) the value that contains HTML tags:
<?php
$str = "Hello world!";
print $str;
print "<br>What a nice day!";
?>
$str = "Hello world!";
print $str;
print "<br>What a nice day!";
?>
Running instance »
Example 3
Connecting two string variables:
<?php
$str1="Hello world!";
$str2="What a nice day!";
print $str1 . " " . $str2;
?>
$str1="Hello world!";
$str2="What a nice day!";
print $str1 . " " . $str2;
?>
Running instance »
Example 4
Output array of values:
<?php
$age=array("Peter"=>"35");
print "Peter is " . $age['Peter'] . " years old.";
?>
$age=array("Peter"=>"35");
print "Peter is " . $age['Peter'] . " years old.";
?>
Running instance »
Example 6
The difference between the single and double quotes. The output variable name in single quotes instead of value ::
<?php
$color = "red";
print "Roses are $color";
print "<br>";
print 'Roses are $color';
?>
$color = "red";
print "Roses are $color";
print "<br>";
print 'Roses are $color';
?>
Running instance »
PHP String Reference