Current Location: Home> Function Categories> print

print

Output a string
Name:print
Category:String
Programming Language:php
One-line Description:Output one or more strings.

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 for it.

Tip: print() function is slightly slower than echo() .

Example

Example 1

Write text to the output:

 <?php
print "I love Shanghai!" ;
?>

Try it yourself

Example 2

Output the value of the string variable ($str):

 <?php
$str = "I love Shanghai!" ;
print $str ;
?>

Try it yourself

Example 3

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

Example 4

Concatenate two string variables:

 <?php
$str1 = "I love Shanghai!" ;
$str2 = "What a nice day!" ;
print $str1 . " " . $str2 ;
?> 

Try it yourself

Example 5

Output array value:

 <?php
$age = array ( "Bill" => "60" ) ;
print "Bill Gates is " . $age [ 'Bill' ] . " years old." ;
?>

Try it yourself

Example 6

Output text:

 <?php
print "This text
spans multiple
lines." ;
?> 

Try it yourself

Example 7

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

grammar

 print ( strings )
parameter describe
strings Required. One or more strings sent to the output.
Similar Functions
Popular Articles