Output some text:
<?php print "Hello world!"; ?>The print() function outputs one or more strings.
Note: The print() function is not actually a function, so you don't have to use parentheses around it.
Tip: The print() function is slightly slower than echo().
print( strings )
parameter | describe |
---|---|
strings | Required. One or more strings sent to the output. |
Return value: | Always returns 1. |
---|---|
PHP version: | 4+ |
Output the value of a string variable ( $str ):
<?php$str = "Hello world!";print $str;?>Output the value of a string variable ( $str ), including HTML tags:
<?php$str = "Hello world!";print $str;print "<br>What a nice day!";?>Concatenate two string variables:
<?php$str1="Hello world!";$str2="What a nice day!";print $str1 . " " . $str2;?>Output the values of the array:
<?php$age=array("Peter"=>"35");print "Peter is " . $age['Peter'] . " years old.";?>Output some text:
<?phpprint "This textspans multiplelines.";?>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';?>