PHP Print
PHP Print Statement
The major differences to echo are that print only accepts a single argument and always returns 1
The print() function used to output one or more string.
- PHP print is a language construct, so you don’t need to use parenthesis with the argument list. Unlike echo, it always returns 1.
- PHP print statement can be used to print a string, multi-line strings, escaping characters, variable, array etc.
The syntax of PHP print like as:
|
1 |
int print(string $arg) |
PHP print: printing string
File: example1.php
|
1 2 3 4 |
<?php print "Welcome PHP print "; print ("Welcome PHP print()"); ?> |
Output:
|
1 |
Welcome PHP print Welcome PHP print() |
PHP print: printing multiline string
File: example2.php
|
1 2 3 4 5 |
<?php print "Web Technologies used for developed website and software for our Business "; ?> |
Output:
|
1 |
Web Technologies used for developed website and software for our Business |
PHP print: printing escaping characters
File: example3.php
|
1 2 3 |
<?php print "Welcome to \"Tutorial Scan\" learn php and more language"; ?> |
Output:
|
1 |
Welcome to "Tutorial Scan" learn php and more language |
PHP print: printing variable value
File: example4.php
|
1 2 3 4 |
<?php $message="Hello print() in PHP Tutorial Scan"; print "Message is: $message"; ?> |
Output:
|
1 |
The message is: Hello print() in PHP Tutorial Scan |
Resource
PHP.Net