SlideShare una empresa de Scribd logo
1 de 7
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Css pseudo-classes
Css pseudo-classesCss pseudo-classes
Css pseudo-classes
 
Popup boxes
Popup boxesPopup boxes
Popup boxes
 
ASP.NET State management
ASP.NET State managementASP.NET State management
ASP.NET State management
 
Css types internal, external and inline (1)
Css types internal, external and inline (1)Css types internal, external and inline (1)
Css types internal, external and inline (1)
 
Html forms
Html formsHtml forms
Html forms
 
JavaScript & Dom Manipulation
JavaScript & Dom ManipulationJavaScript & Dom Manipulation
JavaScript & Dom Manipulation
 
Servlet life cycle
Servlet life cycleServlet life cycle
Servlet life cycle
 
String, string builder, string buffer
String, string builder, string bufferString, string builder, string buffer
String, string builder, string buffer
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
 
Web Service Implementation Using ASP.NET
Web Service Implementation Using ASP.NETWeb Service Implementation Using ASP.NET
Web Service Implementation Using ASP.NET
 
Dom(document object model)
Dom(document object model)Dom(document object model)
Dom(document object model)
 
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
 
Database Connectivity in PHP
Database Connectivity in PHPDatabase Connectivity in PHP
Database Connectivity in PHP
 
Exceptions in python
Exceptions in pythonExceptions in python
Exceptions in python
 
Classes&amp;objects
Classes&amp;objectsClasses&amp;objects
Classes&amp;objects
 
Java Swing
Java SwingJava Swing
Java Swing
 
Oop java
Oop javaOop java
Oop java
 
Html 5-tables-forms-frames (1)
Html 5-tables-forms-frames (1)Html 5-tables-forms-frames (1)
Html 5-tables-forms-frames (1)
 
Php forms
Php formsPhp forms
Php forms
 
Javascript
JavascriptJavascript
Javascript
 

Similar 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
 

Similar 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
 

Más 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

Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmStan Meyer
 
6 ways Samsung’s Interactive Display powered by Android changes the classroom
6 ways Samsung’s Interactive Display powered by Android changes the classroom6 ways Samsung’s Interactive Display powered by Android changes the classroom
6 ways Samsung’s Interactive Display powered by Android changes the classroomSamsung Business USA
 
Satirical Depths - A Study of Gabriel Okara's Poem - 'You Laughed and Laughed...
Satirical Depths - A Study of Gabriel Okara's Poem - 'You Laughed and Laughed...Satirical Depths - A Study of Gabriel Okara's Poem - 'You Laughed and Laughed...
Satirical Depths - A Study of Gabriel Okara's Poem - 'You Laughed and Laughed...HetalPathak10
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research DiscourseAnita GoswamiGiri
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...Nguyen Thanh Tu Collection
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptshraddhaparab530
 
ICS 2208 Lecture Slide Notes for Topic 6
ICS 2208 Lecture Slide Notes for Topic 6ICS 2208 Lecture Slide Notes for Topic 6
ICS 2208 Lecture Slide Notes for Topic 6Vanessa Camilleri
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWQuiz Club NITW
 
Comparative Literature in India by Amiya dev.pptx
Comparative Literature in India by Amiya dev.pptxComparative Literature in India by Amiya dev.pptx
Comparative Literature in India by Amiya dev.pptxAvaniJani1
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Projectjordimapav
 
4.9.24 Social Capital and Social Exclusion.pptx
4.9.24 Social Capital and Social Exclusion.pptx4.9.24 Social Capital and Social Exclusion.pptx
4.9.24 Social Capital and Social Exclusion.pptxmary850239
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxSayali Powar
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvRicaMaeCastro1
 
Tree View Decoration Attribute in the Odoo 17
Tree View Decoration Attribute in the Odoo 17Tree View Decoration Attribute in the Odoo 17
Tree View Decoration Attribute in the Odoo 17Celine George
 
Employablity presentation and Future Career Plan.pptx
Employablity presentation and Future Career Plan.pptxEmployablity presentation and Future Career Plan.pptx
Employablity presentation and Future Career Plan.pptxryandux83rd
 

Último (20)

Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and Film
 
Plagiarism,forms,understand about plagiarism,avoid plagiarism,key significanc...
Plagiarism,forms,understand about plagiarism,avoid plagiarism,key significanc...Plagiarism,forms,understand about plagiarism,avoid plagiarism,key significanc...
Plagiarism,forms,understand about plagiarism,avoid plagiarism,key significanc...
 
Spearman's correlation,Formula,Advantages,
Spearman's correlation,Formula,Advantages,Spearman's correlation,Formula,Advantages,
Spearman's correlation,Formula,Advantages,
 
6 ways Samsung’s Interactive Display powered by Android changes the classroom
6 ways Samsung’s Interactive Display powered by Android changes the classroom6 ways Samsung’s Interactive Display powered by Android changes the classroom
6 ways Samsung’s Interactive Display powered by Android changes the classroom
 
Satirical Depths - A Study of Gabriel Okara's Poem - 'You Laughed and Laughed...
Satirical Depths - A Study of Gabriel Okara's Poem - 'You Laughed and Laughed...Satirical Depths - A Study of Gabriel Okara's Poem - 'You Laughed and Laughed...
Satirical Depths - A Study of Gabriel Okara's Poem - 'You Laughed and Laughed...
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research Discourse
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
 
Introduction to Research ,Need for research, Need for design of Experiments, ...
Introduction to Research ,Need for research, Need for design of Experiments, ...Introduction to Research ,Need for research, Need for design of Experiments, ...
Introduction to Research ,Need for research, Need for design of Experiments, ...
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.ppt
 
Mattingly "AI & Prompt Design" - Introduction to Machine Learning"
Mattingly "AI & Prompt Design" - Introduction to Machine Learning"Mattingly "AI & Prompt Design" - Introduction to Machine Learning"
Mattingly "AI & Prompt Design" - Introduction to Machine Learning"
 
ICS 2208 Lecture Slide Notes for Topic 6
ICS 2208 Lecture Slide Notes for Topic 6ICS 2208 Lecture Slide Notes for Topic 6
ICS 2208 Lecture Slide Notes for Topic 6
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITW
 
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptxINCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
 
Comparative Literature in India by Amiya dev.pptx
Comparative Literature in India by Amiya dev.pptxComparative Literature in India by Amiya dev.pptx
Comparative Literature in India by Amiya dev.pptx
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Project
 
4.9.24 Social Capital and Social Exclusion.pptx
4.9.24 Social Capital and Social Exclusion.pptx4.9.24 Social Capital and Social Exclusion.pptx
4.9.24 Social Capital and Social Exclusion.pptx
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
 
Tree View Decoration Attribute in the Odoo 17
Tree View Decoration Attribute in the Odoo 17Tree View Decoration Attribute in the Odoo 17
Tree View Decoration Attribute in the Odoo 17
 
Employablity presentation and Future Career Plan.pptx
Employablity presentation and Future Career Plan.pptxEmployablity presentation and Future Career Plan.pptx
Employablity presentation and Future Career Plan.pptx
 

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