The print function php

php print function how to use?

Definition and Usage

print () function output one or more strings.

Notes: print () function is actually not a function, so you do not have to use it in parentheses.

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

grammar

print(strings)

parameter

strings necessary. Send to an output of one or more strings.

Returns: always return 1.

PHP Version: 4+

Example 1

Variable output string (STR $) value:

<?php

$str = "I love Shanghai!";

print $str;

?>

Output:

I love Shanghai!

Example 2

Output variable value string (STR $), comprising HTML tags:

<?php

$str = "I love Shanghai!";

print $str;

print "<br>What a nice day!";

?>

Output:

I love Shanghai!

What a nice day!

Example 3

Connecting two string variables:

<?php

$str1 = "I love Shanghai!";

$str2="What a nice day!";

print $str1 . " " . $str2;

?>

Output:

I love Shanghai! What a nice day!

Example 4

Output array values:

<?php

$age=array("Bill"=>"60");

print "Bill Gates is " . $age['Bill'] . " years old.";

?>

Output:

Bill Gates is 60 years old.

Example 5

Output text:

<?php

print "This text

spans multiple

lines.";

?>

Output:

This text spans multiple lines.

Example 6

The difference between the single and double quotes. The output variable name in single quotes instead of value:

<?php

$color = "red";

print "Roses are $color";

print "<br>";

print 'Roses are $color';

?>

Output:

Roses are red

Roses are $color

Example 7

Text written to the output:

<?php

print "I love Shanghai!";

?>

Output:

I love Shanghai!

 

Guess you like

Origin www.cnblogs.com/furuihua/p/10956438.html