Example
Output some text:
<?php print "Hello world!"; ?>
Definition and usage
print() function outputs one or more strings.
Note: The print() function is not actually a function, so you don't have to use parentheses with it.
Tip: The print() function is slightly slower than echo().
Syntax
print(strings)
Parameter Description
strings Required. One or more strings sent to the output.
Technical details
Return value: Always returns 1.
PHP version: 4+
More examples
Example 1
Output the value of the string variable ($str):
<?php $str = "Hello world!"; print $str; ?>
Example 2
Output the value of the string variable ($str), including HTML tags:
<?php $str = "Hello world!"; print $str; print "<br>What a nice day!"; ?>
Example 3
Connect two string variables:
<?php $str1="Hello world!"; $str2="What a nice day!"; print $str1 . " " . $str2; ?>
Example 4
Output the value of the array:
<?php $age=array("Peter"=>"35"); print "Peter is " . $age['Peter'] . " years old."; ?>
Example 5
Output some text:
<?php print "This text spans multiple lines."; ?>
实例 6
单引号和双引号的区别。单引号将输出变量名称,而不是值::
<?php $color = "red"; print "Roses are $color"; print "<br>"; print 'Roses are $color'; ?>
The above is the detailed content of PHP outputs one or more string function print(). For more information, please follow other related articles on the PHP Chinese website!