Home >>PHP String Functions >PHP print() Function
PHP print() function is used to display one or more output strings in the browser. This function can be used with or without parentheses. We can’t pass multiple arguments in this function. This is a return type function which returns the Boolean value true(1).This function works same as the echo(0 function but it is slower than the echo() function.
Syntax:
print($string);
Parameter | Description |
---|---|
string | This is a required parameter. This parameter contain one or more strings to be sent to the browser display as output. |
Here is an example of print() function in PHP:
<html> <body> <?php print "PHP is a server side language."; ?> </body> </html>
Here is an another example of print() function in PHP:
<html> <body> <?php $str = "We love PHP."; print $str; ?> </body> </html>
Here is an example of joining two string variables together in print() function:
<html> <body> <?php $str1="Hello Everyone!!!"; $str2="Have a nice day."; print $str1 . " " . $str2; ?> </body> </html>
Here is an example to see the difference of single and double quotes:
<html> <body> <?php $name = "Jerry"; print "Hi!! My name is $name."; // print the value of the variable print "<br>"; print 'Hi!! My name is $name.'; // print the name of the variable ?> </body> </html>