CodesJava

Easy learning with example program codes

PHP Print


PHP Print is another output statement that is used in PHP. PHP Print is also not a function or a method, hence parenthesis is not necessary with this too. It is a language construct output statement provided by PHP to print single and multi line strings, variables, arrays etc. Parenthesis with PHP is mandatory when using multiple parameters simultaneously. The data type of PHP Print is Int in general, as it always returns 1. This makes it a little bit slower than PHP Echo statement.

Syntax:

int print(string $arg) 

Example 1: Printing text with PHP Print statement

<!DOCTYPE html>
<html>
<body>
 
<?php
print "<h1>Mc Donalds</h1>";
print "Burger!<br>";
print "I'm Loving It!<br>";
?>
 
</body>
</html>

Example 2: Printing Variables with PHP Print statement

<!DOCTYPE html>
<html>
<body>
 
<?php
$txt1 = "Sum of 1234 and 4321 is:";
$x = 1234;
$y = 4321;
 
print "<h3>" . $txt1 . "</h3>";
print $x + $y;
?>
 
</body>
</html>

Example 3: Printing “Hello World” with PHP Print statement

<!DOCTYPE html>
<html>
<body>
 
<?php
$msg = "Hello World";
print "Message is: $msg";
?>
 
</body>
</html>
Posted in PHP   
Sign Up/ Sign In
Ask a Question


Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki