SlideShare uma empresa Scribd logo
1 de 7
Baixar para ler offline
Print Function in PHP

Introduction

PHP is a server side scripting language for creating dynamic web pages. There are so many
functions available for displaying output in PHP. In this article I will explain some basic
functions for displaying output in PHP. The basic functions for displaying output in PHP are
as follows:

      Print() Function
      Echo() Function
      Printf() Function
      Sprintf() Function
      Var_dump() Function
      Print_r() Function

Print() Function

Using this function we can display the outputs in the browser. This function returns the
Boolean value true. We cannot print the multiple statements using this function. The print
function plays the same role as the echo function.

Example1

<html>
<body bgcolor="pink">
<?php
print "Welcome Vineet Kumar Saini !!";
?>
</body>
</html>

Output

In the above example we display a simple message using the print() function.




                      www.vineetsaini.wordpress.com
Example2

<html>
<body bgcolor="pink">
<?php
$rval="Welcome Vineet Kumar Saini is MCA Qualified !!";
print $rval;
?>
</body>
</html>

Output

In the above example we display the message using a variable and the print() function.




Example3

<html>
<body bgcolor="pink">
<?php
print "Welcome Vineet Kumar Saini is "," ","MCA Qualified !!";
?>
</body>
</html>

Output

In the above example we printed two strings using commas but the print() function doesn't
display this message.




                      www.vineetsaini.wordpress.com
Echo() Function

The echo() function outputs one or more strings. Using this function we can display multiple
statements in the browser. The echo() function is slightly faster than print(). Because it
won't return a value.

Example1

<html>
<body bgcolor="pink">
<?php
echo "Welcome Vineet Kumar Saini !!";
?>
</body>
</html>

Output

In the above example we display a simple message using the echo() function.




Example2

<html>
<body bgcolor="pink">


                      www.vineetsaini.wordpress.com
<?php
echo "Welcome Vineet Kumar Saini is "," ","MCA Qualified !!";
?>
</body>
</html>

Output

In the above example we print two strings using commas through the echo() function but
the print() function doesn't display this message. It is the main difference between the
echo() and print() functions.




Printf() Function

The printf() function is also used in C, C++. The printf() function outputs a formatted string.
Using this function we can display the output with the help of the formats specified.

Example

<html>
<body bgcolor="pink">
<?php
$name="Vineet Saini";
$age=24;
printf("The age of %s is %d years.",$name,$age);
?>
</body>
</ html>

Output

In the above example we display the value of two variables i.e. string and integer using the
printf() function.




                       www.vineetsaini.wordpress.com
sprintf() Function

The sprintf() function writes a formatted string to a variable. This is the same as printf, but
instead of displaying the output on the web page, it returns that output. sprintf() prints the
result to a string.

Example

<html>
<body bgcolor="pink">
<?php
$name="Vineet Saini";
$age=24;
$rv=sprintf ("The age of %s is %d years.",$name, $age);
echo $rv;
?>
</body>
</ html>

Output




var_dump() Function




                       www.vineetsaini.wordpress.com
The var_dump() function displays information of a variable that includes its type and
value. This function displays the variable value along with the variable data type. The
var_dump() function is used to display structured information (type and value) about one or
more variables.

Example

<html>
<body bgcolor="pink">
<?php
$name="Vineet Saini";
$age=24;
var_dump($name);
var_dump($age);
?>
</body>
</html>

Output

In the above example we declare two variables i.e. one is string and second is integer
variable. The var_dump() function shows the types of these variables.




print_r() Function

The Print_r() PHP function is used to return an array in a human readable form. This
function displays the elements of an array and properties of an object. The print_r()
function displays human-readable information about a variable.

Example

<html>
<body bgcolor="pink">
<?php
$arr=array ("Vineet","Kumar","Saini");
$arr1=array(10,20,30);
print_r($arr);
print_r($arr1);


                      www.vineetsaini.wordpress.com
?>
</body>
</html>

Output

In the above example we display the element of an array using print_r() function.




Conclusion

So in this article you saw various types of print functions. Using this article one can easily
understand print functions in PHP.




                       www.vineetsaini.wordpress.com

Mais conteúdo relacionado

Mais procurados

Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8LivePerson
 
String classes and its methods.20
String classes and its methods.20String classes and its methods.20
String classes and its methods.20myrajendra
 
Spring Data JPA from 0-100 in 60 minutes
Spring Data JPA from 0-100 in 60 minutesSpring Data JPA from 0-100 in 60 minutes
Spring Data JPA from 0-100 in 60 minutesVMware Tanzu
 
Java string handling
Java string handlingJava string handling
Java string handlingSalman Khan
 
Java variable types
Java variable typesJava variable types
Java variable typesSoba Arjun
 
Java Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepJava Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepGuo Albert
 
String and string buffer
String and string bufferString and string buffer
String and string bufferkamal kotecha
 
Basic Java Programming
Basic Java ProgrammingBasic Java Programming
Basic Java ProgrammingMath-Circle
 
Command line-arguments-in-java-tutorial
Command line-arguments-in-java-tutorialCommand line-arguments-in-java-tutorial
Command line-arguments-in-java-tutorialKuntal Bhowmick
 
Lesson 03 python statement, indentation and comments
Lesson 03   python statement, indentation and commentsLesson 03   python statement, indentation and comments
Lesson 03 python statement, indentation and commentsNilimesh Halder
 

Mais procurados (20)

Java 8 Workshop
Java 8 WorkshopJava 8 Workshop
Java 8 Workshop
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8
 
String classes and its methods.20
String classes and its methods.20String classes and its methods.20
String classes and its methods.20
 
Core java
Core javaCore java
Core java
 
Java 8 Lambda Expressions
Java 8 Lambda ExpressionsJava 8 Lambda Expressions
Java 8 Lambda Expressions
 
Spring Data JPA from 0-100 in 60 minutes
Spring Data JPA from 0-100 in 60 minutesSpring Data JPA from 0-100 in 60 minutes
Spring Data JPA from 0-100 in 60 minutes
 
Java string handling
Java string handlingJava string handling
Java string handling
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
 
Java variable types
Java variable typesJava variable types
Java variable types
 
4.2 PHP Function
4.2 PHP Function4.2 PHP Function
4.2 PHP Function
 
Method overloading
Method overloadingMethod overloading
Method overloading
 
Data types in java
Data types in javaData types in java
Data types in java
 
Java annotations
Java annotationsJava annotations
Java annotations
 
Java Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepJava Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By Step
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
 
Basic Java Programming
Basic Java ProgrammingBasic Java Programming
Basic Java Programming
 
Generic Programming
Generic ProgrammingGeneric Programming
Generic Programming
 
Threads concept in java
Threads concept in javaThreads concept in java
Threads concept in java
 
Command line-arguments-in-java-tutorial
Command line-arguments-in-java-tutorialCommand line-arguments-in-java-tutorial
Command line-arguments-in-java-tutorial
 
Lesson 03 python statement, indentation and comments
Lesson 03   python statement, indentation and commentsLesson 03   python statement, indentation and comments
Lesson 03 python statement, indentation and comments
 

Semelhante a Print function in PHP

Incredible Machine with Pipelines and Generators
Incredible Machine with Pipelines and GeneratorsIncredible Machine with Pipelines and Generators
Incredible Machine with Pipelines and Generatorsdantleech
 
PHP and MySQL : Server Side Scripting For Web Development
PHP and MySQL : Server Side Scripting For Web DevelopmentPHP and MySQL : Server Side Scripting For Web Development
PHP and MySQL : Server Side Scripting For Web DevelopmentEdureka!
 
Sperimentazioni di Tecnologie e Comunicazioni Multimediali: Lezione 5
Sperimentazioni di Tecnologie e Comunicazioni Multimediali: Lezione 5Sperimentazioni di Tecnologie e Comunicazioni Multimediali: Lezione 5
Sperimentazioni di Tecnologie e Comunicazioni Multimediali: Lezione 5Salvatore Iaconesi
 
Vb script tutorial for qtp[1]
Vb script tutorial for qtp[1]Vb script tutorial for qtp[1]
Vb script tutorial for qtp[1]srikanthbkm
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
php-mysql-tutorial-part-3
php-mysql-tutorial-part-3php-mysql-tutorial-part-3
php-mysql-tutorial-part-3tutorialsruby
 
&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/
&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/
&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/tutorialsruby
 
php-mysql-tutorial-part-3
php-mysql-tutorial-part-3php-mysql-tutorial-part-3
php-mysql-tutorial-part-3tutorialsruby
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Muhamad Al Imran
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Muhamad Al Imran
 
Scripting languages
Scripting languagesScripting languages
Scripting languagesteach4uin
 
Web app development_php_06
Web app development_php_06Web app development_php_06
Web app development_php_06Hassen Poreya
 

Semelhante a Print function in PHP (20)

Wt unit 5
Wt unit 5Wt unit 5
Wt unit 5
 
Incredible Machine with Pipelines and Generators
Incredible Machine with Pipelines and GeneratorsIncredible Machine with Pipelines and Generators
Incredible Machine with Pipelines and Generators
 
Php
PhpPhp
Php
 
PHP and MySQL : Server Side Scripting For Web Development
PHP and MySQL : Server Side Scripting For Web DevelopmentPHP and MySQL : Server Side Scripting For Web Development
PHP and MySQL : Server Side Scripting For Web Development
 
Sperimentazioni di Tecnologie e Comunicazioni Multimediali: Lezione 5
Sperimentazioni di Tecnologie e Comunicazioni Multimediali: Lezione 5Sperimentazioni di Tecnologie e Comunicazioni Multimediali: Lezione 5
Sperimentazioni di Tecnologie e Comunicazioni Multimediali: Lezione 5
 
Basic php 5
Basic php 5Basic php 5
Basic php 5
 
Vb script tutorial for qtp[1]
Vb script tutorial for qtp[1]Vb script tutorial for qtp[1]
Vb script tutorial for qtp[1]
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
php-mysql-tutorial-part-3
php-mysql-tutorial-part-3php-mysql-tutorial-part-3
php-mysql-tutorial-part-3
 
&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/
&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/
&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/
 
php-mysql-tutorial-part-3
php-mysql-tutorial-part-3php-mysql-tutorial-part-3
php-mysql-tutorial-part-3
 
Functions in PHP
Functions in PHPFunctions in PHP
Functions in PHP
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
 
Php i basic chapter 3
Php i basic chapter 3Php i basic chapter 3
Php i basic chapter 3
 
Scripting languages
Scripting languagesScripting languages
Scripting languages
 
Web Design EJ3
Web Design EJ3Web Design EJ3
Web Design EJ3
 
Java Script
Java ScriptJava Script
Java Script
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Web app development_php_06
Web app development_php_06Web app development_php_06
Web app development_php_06
 

Mais de Vineet Kumar Saini (20)

Abstract Class and Interface in PHP
Abstract Class and Interface in PHPAbstract Class and Interface in PHP
Abstract Class and Interface in PHP
 
Add edit delete in Codeigniter in PHP
Add edit delete in Codeigniter in PHPAdd edit delete in Codeigniter in PHP
Add edit delete in Codeigniter in PHP
 
Introduction to Html
Introduction to HtmlIntroduction to Html
Introduction to Html
 
Computer Fundamentals
Computer FundamentalsComputer Fundamentals
Computer Fundamentals
 
Country State City Dropdown in PHP
Country State City Dropdown in PHPCountry State City Dropdown in PHP
Country State City Dropdown in PHP
 
Pagination in PHP
Pagination in PHPPagination in PHP
Pagination in PHP
 
Stripe in php
Stripe in phpStripe in php
Stripe in php
 
Php Tutorials for Beginners
Php Tutorials for BeginnersPhp Tutorials for Beginners
Php Tutorials for Beginners
 
Install Drupal on Wamp Server
Install Drupal on Wamp ServerInstall Drupal on Wamp Server
Install Drupal on Wamp Server
 
Joomla 2.5 Tutorial For Beginner PDF
Joomla 2.5 Tutorial For Beginner PDFJoomla 2.5 Tutorial For Beginner PDF
Joomla 2.5 Tutorial For Beginner PDF
 
Sorting arrays in PHP
Sorting arrays in PHPSorting arrays in PHP
Sorting arrays in PHP
 
Dropdown List in PHP
Dropdown List in PHPDropdown List in PHP
Dropdown List in PHP
 
Update statement in PHP
Update statement in PHPUpdate statement in PHP
Update statement in PHP
 
Delete statement in PHP
Delete statement in PHPDelete statement in PHP
Delete statement in PHP
 
Implode & Explode in PHP
Implode & Explode in PHPImplode & Explode in PHP
Implode & Explode in PHP
 
Types of Error in PHP
Types of Error in PHPTypes of Error in PHP
Types of Error in PHP
 
GET and POST in PHP
GET and POST in PHPGET and POST in PHP
GET and POST in PHP
 
Database connectivity in PHP
Database connectivity in PHPDatabase connectivity in PHP
Database connectivity in PHP
 
Arrays in PHP
Arrays in PHPArrays in PHP
Arrays in PHP
 
Programming in C
Programming in CProgramming in C
Programming in C
 

Último

Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 

Último (20)

Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 

Print function in PHP

  • 1. Print Function in PHP Introduction PHP is a server side scripting language for creating dynamic web pages. There are so many functions available for displaying output in PHP. In this article I will explain some basic functions for displaying output in PHP. The basic functions for displaying output in PHP are as follows:  Print() Function  Echo() Function  Printf() Function  Sprintf() Function  Var_dump() Function  Print_r() Function Print() Function Using this function we can display the outputs in the browser. This function returns the Boolean value true. We cannot print the multiple statements using this function. The print function plays the same role as the echo function. Example1 <html> <body bgcolor="pink"> <?php print "Welcome Vineet Kumar Saini !!"; ?> </body> </html> Output In the above example we display a simple message using the print() function. www.vineetsaini.wordpress.com
  • 2. Example2 <html> <body bgcolor="pink"> <?php $rval="Welcome Vineet Kumar Saini is MCA Qualified !!"; print $rval; ?> </body> </html> Output In the above example we display the message using a variable and the print() function. Example3 <html> <body bgcolor="pink"> <?php print "Welcome Vineet Kumar Saini is "," ","MCA Qualified !!"; ?> </body> </html> Output In the above example we printed two strings using commas but the print() function doesn't display this message. www.vineetsaini.wordpress.com
  • 3. Echo() Function The echo() function outputs one or more strings. Using this function we can display multiple statements in the browser. The echo() function is slightly faster than print(). Because it won't return a value. Example1 <html> <body bgcolor="pink"> <?php echo "Welcome Vineet Kumar Saini !!"; ?> </body> </html> Output In the above example we display a simple message using the echo() function. Example2 <html> <body bgcolor="pink"> www.vineetsaini.wordpress.com
  • 4. <?php echo "Welcome Vineet Kumar Saini is "," ","MCA Qualified !!"; ?> </body> </html> Output In the above example we print two strings using commas through the echo() function but the print() function doesn't display this message. It is the main difference between the echo() and print() functions. Printf() Function The printf() function is also used in C, C++. The printf() function outputs a formatted string. Using this function we can display the output with the help of the formats specified. Example <html> <body bgcolor="pink"> <?php $name="Vineet Saini"; $age=24; printf("The age of %s is %d years.",$name,$age); ?> </body> </ html> Output In the above example we display the value of two variables i.e. string and integer using the printf() function. www.vineetsaini.wordpress.com
  • 5. sprintf() Function The sprintf() function writes a formatted string to a variable. This is the same as printf, but instead of displaying the output on the web page, it returns that output. sprintf() prints the result to a string. Example <html> <body bgcolor="pink"> <?php $name="Vineet Saini"; $age=24; $rv=sprintf ("The age of %s is %d years.",$name, $age); echo $rv; ?> </body> </ html> Output var_dump() Function www.vineetsaini.wordpress.com
  • 6. The var_dump() function displays information of a variable that includes its type and value. This function displays the variable value along with the variable data type. The var_dump() function is used to display structured information (type and value) about one or more variables. Example <html> <body bgcolor="pink"> <?php $name="Vineet Saini"; $age=24; var_dump($name); var_dump($age); ?> </body> </html> Output In the above example we declare two variables i.e. one is string and second is integer variable. The var_dump() function shows the types of these variables. print_r() Function The Print_r() PHP function is used to return an array in a human readable form. This function displays the elements of an array and properties of an object. The print_r() function displays human-readable information about a variable. Example <html> <body bgcolor="pink"> <?php $arr=array ("Vineet","Kumar","Saini"); $arr1=array(10,20,30); print_r($arr); print_r($arr1); www.vineetsaini.wordpress.com
  • 7. ?> </body> </html> Output In the above example we display the element of an array using print_r() function. Conclusion So in this article you saw various types of print functions. Using this article one can easily understand print functions in PHP. www.vineetsaini.wordpress.com