Categories: PHP

print – PHP String Functions

Syntax :

print ( strings );

Description :

The print() function outputs one or more strings.

It is not actually a real function (it is a language construct) so you are not required to use parentheses with its argument list.

The major differences to echo() are that print only accepts a single argument and always returns 1.

Note : The print() function is not actually a function, so you are not required to use parentheses with it.
Tip: The print() function is slightly slower than echo().

Parameter :

[table caption=”” width=”100%” colwidth=”15%|15%|15%|55%” colalign=”left|lef|lef|left”]
Name, Required /Optional, Value Type, Description
strings , Required, String , It is the string for which is to be parsed.
[/table]


Output :

print() always Returns 1.


Related articles  : echo(), printf(), flush(), sprintf(), fprintf(), number_format().


print() – PHP Functions Example 1 : Write some text to output.
<?php
print "Hi to all!"; // with parantheses
print "\n";
print ("Hi to all!");  // without parantheses
print "\n";
// multiple lines text

print "This text spans
in multiple lines. This text 
spans in multiple lines.";
print "\n";
//using new line character

print "This text \nspans in multiple lines. This text spans in \nmultiple lines.
This spans\nmultiple lines. The newlines will be\noutput as well.";
print "\n";
//using escaping character
print "\n";
print "escaping characters is done \"Like this\".";
?>

See below is the output of above code in Web browser.

Hi to all!
Hi to all!
This text spans
in multiple lines. This text
spans in multiple lines.
This text
spans in multiple lines. This text spans in
multiple lines.
This spans
multiple lines. The newlines will be
output as well.

escaping characters is done “Like this”.


print() – PHP Functions Example 2 :  You can use variables inside a print statement
<?php
$strName = "Name";
$strValue = "Test";
print "$strName is $strValue";
?>

See below is the output of above code in Web browser.

Name is Test


print() – PHP Functions Example 3 : Arrays example
<?php
$age=array("Arnav"=>"6");
print "Arnav is " . $age['Arnav'] . " years old.";
?>

See below is the output of above code in Web browser.

Arnav is 6 years old.

print() – PHP Functions Example 4 : Single quotes will print the variable name, not the value
<?php
$strName = "Arnav";
print 'Name is $strName';   
?>

See below is the output of above code in Web browser.

Name is $strName


print() – PHP Functions Example 5 : Double quotes will print the  value
<?php
$strName = "Arnav";
print "Name is $strName"; 

// If you are not using any other characters, you can just print variables 
print "\n"; 
print $strName; 
?>

See below is the output of above code in Web browser.

Name is Arnav
Arnav

jyoti rani

Recent Posts

Modern Toys, Magical Moments: Why the Best Toy Shop in Noida Is More Than Just a Store

When it comes to children, there’s one universal truth: the right toy can spark imagination, build skills, and make memories…

6 months ago

Rediscovering Joy: A New Era of Creativity & Comfort in Toy Stores

In today’s digital age, where screens and gadgets dominate our children’s lives, there’s something heartwarming about a well-loved plush toy…

6 months ago

Unboxing Imagination: Discovering the Joy of Play at a Toy Store in Noida

In a world dominated by screens and fast-paced routines, it’s easy to forget the simple magic of a toy in…

6 months ago

Imagination Unboxed: Discover Joy at the Toy Shop in Delhi

In the heart of Delhi’s vibrant streets lies a world where imagination meets innovation — the magical universe of toys.…

6 months ago

Play with Purpose: Discovering the Ultimate Toy Store in Noida

When was the last time a toy truly amazed you—not just as a product, but as a thoughtful tool for…

6 months ago

From Tears to Toys: Exploring Modern Childhood through Delhi’s Favorite Toy Shop

In the digital age, the way we experience childhood has changed, but the essence remains the same—imagination, exploration, and joy.…

6 months ago