Your SlideShare is downloading. ×
Print function in PHP
Print function in PHP
Print function in PHP
Print function in PHP
Print function in PHP
Print function in PHP
Print function in PHP
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Print function in PHP

1,910

Published on

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,910
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
17
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Print Function in PHPIntroductionPHP is a server side scripting language for creating dynamic web pages. There are so manyfunctions available for displaying output in PHP. In this article I will explain some basicfunctions for displaying output in PHP. The basic functions for displaying output in PHP areas follows:  Print() Function  Echo() Function  Printf() Function  Sprintf() Function  Var_dump() Function  Print_r() FunctionPrint() FunctionUsing this function we can display the outputs in the browser. This function returns theBoolean value true. We cannot print the multiple statements using this function. The printfunction plays the same role as the echo function.Example1<html><body bgcolor="pink"><?phpprint "Welcome Vineet Kumar Saini !!";?></body></html>OutputIn 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>OutputIn the above example we display the message using a variable and the print() function.Example3<html><body bgcolor="pink"><?phpprint "Welcome Vineet Kumar Saini is "," ","MCA Qualified !!";?></body></html>OutputIn the above example we printed two strings using commas but the print() function doesntdisplay this message. www.vineetsaini.wordpress.com
  • 3. Echo() FunctionThe echo() function outputs one or more strings. Using this function we can display multiplestatements in the browser. The echo() function is slightly faster than print(). Because itwont return a value.Example1<html><body bgcolor="pink"><?phpecho "Welcome Vineet Kumar Saini !!";?></body></html>OutputIn the above example we display a simple message using the echo() function.Example2<html><body bgcolor="pink"> www.vineetsaini.wordpress.com
  • 4. <?phpecho "Welcome Vineet Kumar Saini is "," ","MCA Qualified !!";?></body></html>OutputIn the above example we print two strings using commas through the echo() function butthe print() function doesnt display this message. It is the main difference between theecho() and print() functions.Printf() FunctionThe 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>OutputIn the above example we display the value of two variables i.e. string and integer using theprintf() function. www.vineetsaini.wordpress.com
  • 5. sprintf() FunctionThe sprintf() function writes a formatted string to a variable. This is the same as printf, butinstead of displaying the output on the web page, it returns that output. sprintf() prints theresult 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>Outputvar_dump() Function www.vineetsaini.wordpress.com
  • 6. The var_dump() function displays information of a variable that includes its type andvalue. This function displays the variable value along with the variable data type. Thevar_dump() function is used to display structured information (type and value) about one ormore variables.Example<html><body bgcolor="pink"><?php$name="Vineet Saini";$age=24;var_dump($name);var_dump($age);?></body></html>OutputIn the above example we declare two variables i.e. one is string and second is integervariable. The var_dump() function shows the types of these variables.print_r() FunctionThe Print_r() PHP function is used to return an array in a human readable form. Thisfunction 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>OutputIn the above example we display the element of an array using print_r() function.ConclusionSo in this article you saw various types of print functions. Using this article one can easilyunderstand print functions in PHP. www.vineetsaini.wordpress.com

×