Output a string
print()
function outputs one or more strings.
Note: The print()
function is not actually a function, so you don't have to use parentheses for it.
Tip: print()
function is slightly slower than echo()
.
Write text to the output:
<?php print "I love Shanghai!" ; ?>
Try it yourself
Output the value of the string variable ($str):
<?php $str = "I love Shanghai!" ; print $str ; ?>
Try it yourself
Output the value of the string variable ($str), containing HTML tags:
<?php $str = "I love Shanghai!" ; print $str ; print "<br>What a nice day!" ; ?>
Try it yourself
Concatenate two string variables:
<?php $str1 = "I love Shanghai!" ; $str2 = "What a nice day!" ; print $str1 . " " . $str2 ; ?>
Try it yourself
Output array value:
<?php $age = array ( "Bill" => "60" ) ; print "Bill Gates is " . $age [ 'Bill' ] . " years old." ; ?>
Try it yourself
Output text:
<?php print "This text spans multiple lines." ; ?>
Try it yourself
The difference between single quotes and double quotes. Single quotes will output the variable name, not the value:
<?php $color = "red" ; print "Roses are $color " ; print "<br>" ; print 'Roses are $color' ; ?>
Try it yourself
print ( strings )
parameter | describe |
---|---|
strings | Required. One or more strings sent to the output. |