PHP Print  

PHP Print

PHP Print

Like PHP echo, PHP print is a language construct, so you don't need to use parenthesis with the argument list. Unlike echo, it always returns 1.

The syntax of PHP print is given below:

  1. int print(string $arg)  

PHP print statement can be used to print string, multi line strings, escaping characters, variable, array etc.

PHP print: printing string

File: print1.php

  1. <?php  
  2. print "Hello by PHP print ";  
  3. print ("Hello by PHP print()");  
  4. ?>  


Hello by PHP print Hello by PHP print()

PHP print: printing multi line string

File: print2.php

  1. <?php  
  2. print "Hello by PHP print  
  3. this is multi line  
  4. text printed by   
  5. PHP print statement  
  6. ";  
  7. ?>  


Hello by PHP print this is multi line text printed by PHP print statement

PHP print: printing escaping characters

File: print3.php

  1. <?php  
  2. print "Hello escape \"sequence\" characters by PHP print";  
  3. ?>  


Hello escape "sequence" characters by PHP print

PHP print: printing variable value

File: print4.php

  1. <?php  
  2. $msg="Hello print() in PHP";  
  3. print "Message is: $msg";    
  4. ?>  


Message is: Hello print() in PHP


Download free E-book of PHP

Learn Programming for Free

Join Programmers Community on Telegram

Talk with Experienced Programmers

Just drop a message, we will solve your queries