your image

PHP Print - javatpoint

javapoint
Related Topic
:- PHP

PHP Print

Like PHP echo, PHP print is a language construct, so you don't need to use parenthesis with the argument list. Print statement can be used with or without parentheses: print and print(). 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 the string, multi-line strings, escaping characters, variable, array, etc. Some important points that you must know about the echo statement are:

  • print is a statement, used as an alternative to echo at many times to display the output.
  • print can be used with or without parentheses.
  • print always returns an integer value, which is 1.
  • Using print, we cannot pass multiple arguments.
  • print is slower than the echo statement.

PHP print: printing string

File: print1.php

 

 

1. Build a CMS using OOP PHP tutorial | PHP MVC design pattern [2020]

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

Output:

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. ?>  

Output:

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. ?>  

Output:

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. ?>  

Output:

Message is: Hello print() in PHP

Comments