PHP Kya Hai




PHP एक Server Side Scripting Language है. PHP का उपयोग Webpages को Dynamic Develop करने के लिए किया जाता है. PHP एक ऐसी Scripting Language है जिसका उपयोग Web Applications और Webpage को Server Side मे Control करने के लिए किया जाता है.

PHP Web पर उपयोग होने वाली सबसे लोकप्रिय Scripting Language है . PHP का उपयोग करके आप User का Name और Password का Login Page बना सकते है. PHP के उपयोग से आप Forum भी बना सकते है.

PHP Advantages

  • Open source − PHP उपयोग के लिए स्वतंत्र रूप से उपलब्ध है . PHP Open Source Developers का समुदाय तकनीकी सहायता प्रदान करता है और Core PHP Functionalities को Updates करने में लगातार सुधार कर रहा है.

  • Cross-Platform − PHP Leading Operating Systems और Web Servers जैसी High Consistency प्रदान करता है जिससे कि यह आसानी से कई विभिन्न Platforms में तैनात किया जा सके. PHP Scripts Operating Systems जैसे कि Linux, Windows, Solaris, OpenBSD, Mac OSX इत्यादि में चला सकते हैं और Apache, IIS, iPlanet इत्यादि जैसे सभी प्रमुख Web Servers के लिए समर्थन भी प्रदान कर सकते है.

  • Power − कई Web Tasks को अब आसानी से PHP का उपयोग करके किया जा सकता है. अब हम छोटी Websites से विशाल Business और Organizational Websites Informative Forums, Chatting Platforms, CRM Solutions, E-commerce Shopping Carts, Community Websites, e-business, Shopping Carts और विशाल Database Sites से Develop कर सकते है.

  • User Friendly − User के अनुकूल तरीके से बनाया गया PHP C, C++ और ASP से अधिक Flexibility देता है और Site पर Traffic बढ़ाने में मदद करता है.

  • Quick − PHP को Web के साथ अच्छी तरह से काम करने के लिए Design किया गया है और इस प्रकार GET और POST को Access करने और HTML और URLs के साथ काम करने जैसी चीजें PHP Language मे Manufactured है.

PHP Disadvantages

  • PHP बड़ी Applications के लिए उपयुक्त नहीं है इसे बनाए रखने मे Difficul होती है क्योंकि यह बहुत Modular नहीं है.

  • PHP Framework मे एक खराब Error Handling Method है. यह PHP Developers के लिए उचित Solution नहीं है इसलिए यह एक योग्य PHP Developer के रूप मे आपको इस Problem का सामना करना होता है.

PHP in Hindi Introduction

PHP (Hypertext Preprocessor) एक Open Source HTML Embedded सर्वर साइड स्क्रिप्टिंग भाषा है जो Web Applications को Dynamic और Interactive बनाने के लिये उपयोग कि जाती है और इसे सामान्य Programming भाषा के रूप में भी इस्तेमाल किया जाता है.

PHP की विशेषताएं

  • PHP Website बनाने के लिये बहुत कम समय लेती है.

  • PHP सीखने के लिए आसान है और ये Server Side पर कुशलतापूर्वक Runs भी होती है.

  • PHP कई Operating Systems जैसे Linux, Windows, Mac OS X और कई अन्य पर कार्य करती है.

  • PHP बहुत से Databases जैसे MySQL, MS-SQL , Oracle, Sybase, PostgreSQL का समर्थन करती है.

  • किसी भी Newcomer के लिये PHP का उपयोग सबसे आसान है क्योकि इसमे उन्नत सुविधाओं और Professional Programming भी जोड़ी की गई है.

For Example

<!DOCTYPE html>
<html>   
   <head>
      <title>PHP Hello World Example</title>
   </head>   
   <body>
   <?php
      echo "Hello World...! ";
      echo "This is basic example";
   ?>
   </body>
</html>

Output

PHP in Hindi Variables

एक Variable Data Type के लिए एक Holder होता है. इसलिए इसके Type के आधार पर, एक Variable Numbers, Strings, Booleans, Objects के Resources को Hold कर सकता है या यह NULL कर सकता है .

PHP में सभी Variable एक Sign "$" से शुरू होते हैं और इसमे "=" operator का उपयोग करके Value को Assign किया जा सकता है . Dollar Sign तकनीकी रूप से Variable के Name का हिस्सा नहीं है लेकिन PHP Parser के पहले वर्ण के रूप में इस तरह के Variable को पहचानना आवश्यक होता है .

PHP मे एक और महत्वपूर्ण बात यह है कि सभी Statements को एक semicolon ";" के साथ ही समाप्त करना चाहिए. PHP मे हमे Variable के Type को Specify करने की ज़रूरत नहीं है क्योंकि यह Assign की गई Value से Data Type को लेता है.

एक Variable को Declare करने के लिए आपको इसे अपनी Script में शामिल करना होगा. आप एक Variable को Declare कर सकते हैं और उसे एक ही Statement मे एक Value के साथ Assign कर सकते है.

Rules for Variable Declaration

  • Variable Numbers से शुरू नहीं होता है.

  • Variable $ Sign से शुरू होता है और Variable Name के साथ.

  • Variable Name Letter या Underscore Sign से शुरू होते है उसके बाद Underscore Number या Characters होते है.

  • Variable को alpha-numeric Characters का उपयोग करके और केवल Underscores करके Define किया जा सकता है.

PHP Variable Scope

Scope केवल Rules के अलावा कुछ नहीं होता है जब दो अलग-अलग Places के नाम का अर्थ समान अर्थ है. PHP मे Places को Define करने के लिये तीन Variable Scope है.

  • Local Variable Scope

  • Global Variable Scope

  • Static Variable Scope

Local Variable Scope

Local Variable को Function के भीतर Define और Access किया जाता है. ये Function के बाहर Accessible नहीं है.

For Example

<!DOCTYPE html>
<html>   
   <head>
      <title>Local Variables Example</title>
   </head>   
   <body>
      <?php 
         function myTest() {
            $x = 6; 
            echo "<p>Variable x inside function is: $x</p>";
         } 
         myTest();
         echo "<p>Variable x outside function is: $x</p>"; 
      ?>
   </body>
</html>

Output

Variable x inside function is: 6
Variable x outside function is:

Global Variable Scope

Global Variable को Function के बाहर Define किया जाता है. Function के बाहर Script में कहीं भी आप Global Variable का उपयोग कर सकते है. लेकिन Global Variable को Function के अंदर भी Access किया जा सकता है Variable को Declared होने से पहले Keyword Global का उपयोग करके.

For Example

<!DOCTYPE html>
<html>   
   <head>
      <title>Global Variables Example</title>
   </head>   
   <body>
      <?php 
         $x = 6; 
         function myTest() {    
            echo "<p>Variable x inside function is: $x</p>";
         } 
         myTest();
         echo "<p>Variable x outside function is: $x</p>"; 
      ?>
   </body>
</html>

Output

Variable x inside function is:
Variable x outside function is: 6

Static Variable Scope

आम तौर पर जब कोई Function Completed Executed होता है तो उसके सभी Variables Delete कर दिये जाते है. हालांकि कभी-कभी हम एक Local Variable को हटाना नहीं चाहते है. हमें इसे और Further के लिए चाहिए होता है . ऐसा करने के लिए आपको Static Keyword का उपयोग करके और पहले Variable को Declare करना होता है.

For Example

<!DOCTYPE html>
<html>   
   <head>
      <title>Static Variables Example</title>
   </head>   
   <body>
      <?php 
         $a = 70; 
            $b = 105; 
             
            function myVariables() { 
            static $a, $b; 
            $b = $a + $b; 
            }
              
            myVariables();
            echo "The valuse of b is:". $b; 
      ?>
   </body>
</html>

Output

The valuse of b is:105

PHP in Hindi Data Types

Data Types सामान्य Type के होते हैं जो किसी विशेष Type की Value को Storage करने की अनुमति देते है. Data Type आकार और Type की Value को को Specified करते है जिनको Stored किया जा सकता है. Variable को Data Type की Value को Declared करने की ज़रूरत नहीं होती है. PHP मे Data Type की जांच के लिए gettype() Function का उपयोग करते है.

PHP मे कुछ Defined Variables Values को Stored करते है जब भी आप किसी भी Variable को बनाने का प्रयास करते है आपको तो हर बार Variable के लिए Data Type को Define करने की आवश्यकता नहीं होती है. लेकिन कभी कभी Situation ऐसे हो सकती है की जब Data Type की पहचान करने की आवश्यकता होती है तो तब Data Type आपके Type के Data को Specified करता है. जिसको आप अपने Variable मे Stored कर सकते है.

PHP निम्नलिखित Data Type को Supports करता है.

  • String

  • Integer

  • Float

  • Boolean

  • Array

  • Object

  • NULL

  • Resource

PHP String

एक String Characters का अनुक्रम होता है.

<!DOCTYPE html>
<html>   
   <head>
      <title>PHP String Example</title>
   </head>   
   <body>
      <?php 
         $x = "Hello world!";
         $y = 'Hello world!';

         echo $x;
         echo "<br>"; 
         echo $y;
      ?>

   </body>
</html>

Output

PHP String Example Hello world!
Hello world!

PHP Integer

कोई भी Integer एक Data Type और non-decimal Number के बीच होता है -2,147,483,648 and 2,147,483,647.

<!DOCTYPE html>
<html>   
   <head>
      <title>PHP Integer Example</title>
   </head>   
   <body>
      <?php 
         $x = 5985;
         var_dump($x);
      ?>

   </body>
</html>

Output

PHP Float

एक Float Decimal Digits के साथ एक Number या Exponent Form मे एक Number होता है.

<!DOCTYPE html>
<html>   
   <head>
      <title>PHP Float Example</title>
   </head>   
   <body>
      <?php 
         $x = 20.465;
         var_dump($x);
      ?>
   </body>
</html>

Output

PHP Boolean

Boolean एक Switch की तरह होता है और इसमे केवल दो Possible Values होती है TRUE या FALSE.

<!DOCTYPE html>
<html>   
   <head>
      <title>PHP Boolean Example</title>
   </head>   
   <body>
      <?php 
         $x = true;
         $Y = false;
      ?>
   </body>
</html>

Output

PHP Boolean Example

PHP Array

एक Array Multiple Values को एक Single Variable मे Store करता है.

<!DOCTYPE html>
<html>
<body>

<?php
$cars = array
  (
  array("Volvo",22,18),
  array("BMW",15,13),
  array("Saab",5,2),
  array("Land Rover",17,15)
  );
  
echo $cars[0][0].": In stock: ".$cars[0][1].", sold: ".$cars[0][2].".<br>";
echo $cars[1][0].": In stock: ".$cars[1][1].", sold: ".$cars[1][2].".<br>";
echo $cars[2][0].": In stock: ".$cars[2][1].", sold: ".$cars[2][2].".<br>";
echo $cars[3][0].": In stock: ".$cars[3][1].", sold: ".$cars[3][2].".<br>";
?>

</body>
</html>

Output

Volvo: In stock: 22, sold: 18.
BMW: In stock: 15, sold: 13.
Saab: In stock: 5, sold: 2.
Land Rover: In stock: 17, sold: 15.

PHP Object

Object एक Data Type है जो Conjunct Data और जानकारी को Store करता है.

<!DOCTYPE html>
<html>   
   <head>
      <title>PHP Object Example</title>
   </head>   
   <body>
      <?php 
         class Car {
            function Car() {
              $this->model = "VW";
            }
         }
         // create an object
         $herbie = new Car();

         // show object properties
         echo $herbie->model;
      ?>
   </body>
</html>

Output

PHP Object Example VW

PHP NULL Value

Null Value एक विशेष Data Type है जिसमें केवल एक Value होती है.

<!DOCTYPE html>
<html>   
   <head>
      <title>PHP NULL Value Example</title>
   </head>   
   <body>
      <?php 
         $x = "Hello world!";
         $x = null;
         var_dump($x);
      ?>

   </body>
</html>

Output

PHP in Hindi Operators

Operators का उपयोग Data को Developed करने के लिए किया जाता है. Programming Languages मे Operators को Mathematics से लिया जाता है और Operator Programmers Data के साथ काम करते है.

Operator एक Symbols की एक Chain है जो कुछ Values के साथ प्रयोग किया जाता है. Variables और Values पर संचालन करने के लिए हम Operators का उपयोग करते है.

PHP भाषा बहुत से प्रकार के Operators का समर्थन करती है.

  • Arithmetic Operators

  • Comparison Operators

  • Assignment Operators

  • Logical Operators

  • Conditional Operators

Arithmetic Operators

Arithmetic Operators को variables के साथ Arithmetic Operations Perform करने के लिए उपयोग किया जाता है. PHP भाषा मे इन + , - , * , / , % , ++ , -- Arithmetic Operators का उपयोग किया जाता है.

Operatos Description
+ Add
- Subtract
* Multiply
/ Divide and return quotient
% Divide and return modulus

For Example

<!DOCTYPE html>
<html>   
   <head>
      <title>PHP Arithmetic Operators Example</title>
   </head>   
   <body>
   <?php
	
      $var1 = 28;
      $var2 = 78;
      
      $res = $var1 + $var2;
      echo "Addtion Result is $res <br/>";
      
      $res = $var2 - $var1;
      echo "Substraction Result is $res <br/>";
      
      $res = $var1 * $var2;
      echo "Multiplication Result is $res <br/>";
      
      $res = $var1 / $var2;
      echo "Division Result is $res <br/>";
      
      $res = $var1 % $var2;
      echo "Modulus Result is $res <br/>";
      
      $res = $var1++; 
      echo "Increment Result is $res <br/>";
      
      $res = $var1--; 
      echo "Decrement Result is $res <br/>";
   ?>
   </body>
</html>

Output

Addtion Result is 106
Substraction Result is 50
Multiplication Result is 2184
Division Result is 0.35897435897436
Modulus Result is 28
Increment Result is 28
Decrement Result is 29

Comparison Operators

Comparison Operators दो Variables की Values को Compare करने के लिए उपयोग किया जाता है. PHP भाषा मे इन == , != , > , < , >= , <= Comparison Operators का उपयोग किया जाता है.

Operatos Description
== Equal to
=== Equal to and of the same type
!= Not equal to
!== Not equal to and of the same type
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to

For Example

<!DOCTYPE html>
<html>   
   <head>
      <title>PHP Comparison Operators Example</title>
   </head>   
   <body>
   <?php
      
      $a = 65;
      $b = 85;
      
      if( $a == $b ){
         echo "a is equal to b <br/>";
      }
      else{
         echo "a is not equal to b <br/>";
      }
   
      if( $a > $b ){
         echo "a is greater than  b <br/>";
      }
      else{
         echo "a is not greater than b <br/>";
      }
   
      if( $a < $b ){
         echo "a is less than  b <br/>";
      }
      else{
         echo "a is not less than b <br/>";
      }
   
      if( $a != $b ){
         echo "a is not equal to b <br/>";
      }
      else{
         echo "a is equal to b <br/>";
      }
   
      if( $a >= $b ){
         echo "a is either greater than or equal to b <br/>";
      }
      else{
         echo "a is neither greater than nor equal to b <br/>";
      }
   
      if( $a <= $b ){
         echo "a is either less than or equal to b <br/>";
      }
      else{
         echo "a is neither less than nor equal to b <br/>";
      }
   ?>
   </body>
</html>

Output

a is not equal to b
a is not greater than b
a is less than b
a is not equal to b
a is neither greater than nor equal to b
a is either less than or equal to b

Assignment Operators

Assignment Operators को एक Variable में Value लिखने के लिए Numeric Values के साथ उपयोग किया जाता है. PHP भाषा मे इन = , += , -= , *= , /= , %= Assignment Operators का उपयोग किया जाता है.

Operatos Description
+= Add and assign
-= Subtract and assign
*= Multiply and assign
/= Divide and assign quotient
%= Divide and assign modulus
.= Concatenate and assign

For Example

<!DOCTYPE html>
<html>   
   <head>
      <title>PHP Assignment Operators Example</title>
   </head>   
   <body>
   <?php
      
      $a = 35;
      $b = 50;
      
      $res = $a + $b;   
      echo "Addtion Operation Result: $res <br/>";
      
      $res += $a;  
      echo "Add and Assigment Operation Result: $res <br/>";
      
      $res -= $a; 
      echo "Subtract and Assignment Operation Result: $res <br/>";
      
      $res *= $a; 
      echo "Multiply and Assignment Operation Result: $res <br/>";
      
      $res /= $a;  
      echo "Division and Assignment Operation Result: $res <br/>";
      
      $res %= $a; 
      echo "Modulus and Assignment Operation Result: $res <br/>";
   ?>
   </body>
</html>

Output

Addtion Operation Result: 85
Add and Assigment Operation Result: 120
Subtract and Assignment Operation Result: 85
Multiply and Assignment Operation Result: 2975
Division and Assignment Operation Result: 85
Modulus and Assignment Operation Result: 15

Logical (or Relational) Operators

Logical Operators Logic Perform करने के लिए उपयोग किया जाता है और ये Operators Control Statements में भी प्रयोग किया जाता है. PHP भाषा मे इन and , or , && , || , ! Logical Operators का उपयोग किया जाता है.

Operatos Description
&& And
|| Or
! Not

For Example

<!DOCTYPE html>
<html>   
   <head>
      <title>PHP Logical Operators Example</title>
   </head>   
   <body>
   <?php
      
      $a = 0;
      $b = 21;
      
      if( $a && $b ){
         echo "Both a and b are true<br/>";
      }
      else{
         echo "Either a or b is false<br/>";
      }
      
      if( $a and $b ){
         echo "Both a and b are true<br/>";
      }
      else{
         echo "Either a or b is false<br/>";
      }
      
      if( $a || $b ){
         echo "Either a or b is true<br/>";
      }
      else{
         echo "Both a and b are false<br/>";
      }
      
      if( $a or $b ){
         echo "Either a or b is true<br/>";
      }
      else{
         echo "Both a and b are false<br/>";
      }
               
      if( !$a ){
         echo "a is true <br/>";
      }
      else{
         echo "a  is false<br/>";
      }
   ?>
   </body>
</html>

Output

Either a or b is false
Either a or b is false
Either a or b is true
Either a or b is true
a is true

Conditional Operators

PHP भाषा मे इन " ?: " (If Condition is true ? Then true value : Otherwise false value) Conditional Operators का उपयोग किया जाता है. Conditional Operators को Ternary Operators भी कहा जाता है.

For Example

<!DOCTYPE html>
<html>   
   <head>
      <title>PHP Conditional/Ternary Operator Example</title>
   </head>   
   <body>
   <?php
      
      $a = 50;
      $b = 35;         
      
      $res = ($a > $b ) ? $a ." is greater than ". $b  : $b." is greater than ". $a;         
      echo "The result :: $res";   
   ?>
   </body>
</html>

Output

The result :: 50 is greater than 35

PHP in Hindi Functions

PHP मे Function का उपयोग Code के Reduplication को कम करने के लिए किया जाता है. Function के उपयोग से Code की Clarity मे सुधार किया जाता है Function सरल Pieces मे Complex Problems को भी कम कर देता है.

Function Statement का एक Section होता है जिसका उपयोग किसी कार्यक्रम में बार-बार किया जा सकता है. यह Page के Load होने पर तत्काल Execute नहीं होता है इसे Function पर Call करके Execute किया जाता है.

Function Code का एक Piece है जो Parameter के रूप में Input लेता है और Processing के बाद एक Value Return देता है. PHP मे Function अन्य Programming Language के कार्यों के समान होती है. इसको Declare करने के लिए Function Keywords की आवश्यकता होती है.

Function को Body मे Define या Execute किया जाता है जो Curly Bracket के बीच मे होता है.

PHP Language में हजारों built-in Functions हैं.

Functions With Parameters

PHP आपको एक functions के अंदर अपने Parameters को पास करने का विकल्प देता है जिससे आप ज्यादा Parameters को पास कर सकते है.

For Example

<!DOCTYPE html>
<html>   
   <head>
      <title>Function with Parameters Example</title>
   </head>   
   <body>
   <body>      
      <?php
         function addNumbers($param1, $param2)
         {
            $total = $param1 + $param2;
            echo "Total of the two numbers is : $total";
         }         
         addNumbers(35, 60);     
      ?>      
   </body>
</html>

Output

Total of the two numbers is : 95

Passing Arguments by Reference

Functions को Reference द्वारा Arguments भेजना संभव है. इसका मतलब है कि Variable के Reference में Functions के द्वारा Variable की Value को कापी के बजाय हेरफेर किया जाता है.

For Example

<!DOCTYPE html>
<html>   
   <head>
      <title>Passing Arguments by Reference Example</title>
   </head>   
   <body>     
      <?php
         $original = 30;
         function changeValue(&$param)
         {
            $param = 25;
         }    
         echo "Original Value is $original <br />";
 
         changeValue( $original );
         
         echo "Changed Original Value is $original <br />";        
      ?>     
   </body>
</html>

Output

Original Value is 30
Changed Original Value is 25

Dynamic Function

Function के नाम को Variables के रूप में Assign करना मुमकिन है और फिर इन Variables को उसी तरह से व्यवहार करना चाहिए जैसा आप Function नाम ही करेंगे.

For Example

<!DOCTYPE html>
<html>   
   <head>
      <title>Dynamic Function Example</title>
   </head>   
   <body>     
      <?php
         function printText()
         {
            echo "You are calling printText function dynamically.";
         }
         $function_string = "printText";
         $function_string();        
      ?>     
   </body> 
</html>

Output

You are calling printText function dynamically.

Function Returning Value

एक Function Value या Object के साथ संयोजन के साथ Return Statement का उपयोग करके एक Value को वापस कर सकता है. Return Function के निष्पादन को बंद कर देता है और Value वापस कॉलिंग कोड को भेजता है.

For Example

<!DOCTYPE html>
<html>   
   <head>
      <title>Function Returning Value Example</title>
   </head>   
   <body>      
      <?php
         function addNumbers($param1, $param2)
         {
            $total = $param1 + $param2;
            return $total;
         }         
         $sum = addNumbers(46, 31);
         echo "Total of the two numbers is : $sum";        
      ?>      
   </body>
</html>

Output

Total of the two numbers is : 77

PHP in Hindi Strings

PHP मे String Characters का एक Sequence है जो कि Text को Stored और हेर फेर करने के लिए उपयोग किया जाता है. Strings को किसी Person, Place या किसी अन्य Character पर आधारित Value, Name, आदि को Stored करने के लिए उपयोग करते है. PHP मे एक Strings को Single या Double Quotation Marks के भीतर Text को Attachment करके बनाया जाता है.

PHP मे String को Specify करने के चार तरीके है.

  • single quoted

  • double quoted

  • heredoc syntax

  • newdoc syntax

Single Quoted String

हम एक Single Quote में Text संलग्न करके PHP में स्ट्रिंग बना सकते हैं. यह PHP में String Specify करने का सबसे आसान तरीका है.

For Example

<!DOCTYPE html>
<html>   
   <head>
      <title>Single Quoted String Example</title>
   </head>   
   <body>
   <body>      
      <?php
         $str='Hello text within single quote';  
         echo $str;     
      ?>      
   </body>
</html>

Output

Hello text within single quote

Double Quoted String

PHP में, हम String को Double Quote के भीतर Text को Attached करके भी Specify कर सकते हैं. लेकिन Escape Sequences और Variables को Double Quote PHP String का उपयोग करके व्याख्या की जाएगी.

For Example

<!DOCTYPE html>
<html>   
   <head>
      <title>Double Quoted String Example</title>
   </head>   
   <body>     
      <?php
         $str1="Hello text   
         multiple line  
         text within double quoted string";  
         $str2="Using double \"quote\" with backslash inside double quoted string";  
         $str3="Using escape sequences \n in double quoted string";  
         echo "$str1 <br/> $str2 <br/> $str3";         
      ?>     
   </body>
</html>

Output

Hello text multiple line text within double quoted string
Using double "quote" with backslash inside double quoted string
Using escape sequences in double quoted string

PHP in Hindi Form Handling

Handling Form किसी भी PHP Developer द्वारा किए गए सबसे सामान्य कार्यों में से एक है. क्योंकि सामान्य रूप से हम Form के द्वारा हमारे Web Application के साथ User Interaction को बनाते है.

PHP मे form-data को Collect करने के लिए Superglobals $_GET और $_POST का उपयोग किया जाता है.

For Example

<!DOCTYPE html>
<html>
   <head>
      <title>Form Handling Example</title>
   </head>
   <body>
      <h2>Form Handling Example</h2>
      <p>Please fill in this form and send us.</p>
      <form action="process-form.php" method="post">
         <p>
            <label for="inputName">Name:<sup>*</sup></label>
            <input type="text" name="name" id="inputName">
         </p>
         <p>
            <label for="inputEmail">Email:<sup>*</sup></label>
            <input type="text" name="email" id="inputEmail">
         </p>
         <p>
            <label for="inputSubject">Subject:</label>
            <input type="text" name="subject" id="inputSubject">
         </p>
         <p>
            <label for="inputComment">Message:<sup>*</sup></label>
            <textarea name="message" id="inputComment" rows="5" cols="30">
            </textarea>
         </p>
         <input type="submit" value="Submit">
         <input type="reset" value="Reset">
      </form>
   </body>
</html>

Output

Capturing Form Data with PHP

किसी Particular Form Field की Value तक पहुंचने के लिए आप बहुत से Superglobals Variables का उपयोग कर सकते हैं.

Superglobal Description
$_GET Get Method यानी (URL Parameters) का उपयोग करके सभी Field Names और Form द्वारा भेजी गई मान की एक सूची है.
$_POST Post Method का उपयोग करके सभी Field Names और Form द्वारा भेजी गई मान की एक सूची है. लेकिन इसमे Data URL में दिखाई नहीं देता है.
$_REQUEST इसमें $ _GET और $ _POST Variables के मान के साथ-साथ $ _COOKIE Superglobal Variable के मान भी शामिल होते है.

PHP in Hindi Sessions

PHP मे Sessions का उपयोग Server पर Information को Stored करने के लिए किया जाता है. Data एक Application मे सभी Pages पर उपलब्ध होता है एक Sessions कई Pages मे उपयोग की जाने वाली Information को रखने का एक Best तरीका है.

Session को आप एक Page से दूसरे Page पर Temporary रूप से Information को Stored और Pass करने के लिए उपयोग किया जाता है जब तक कि User Website को Close ना करे तब तक Cookie के द्वारा Information User के Computer मे Stored होती रहती है लेकिन Session की Information User के Computer पर Stored नहीं होती है.

Session प्रत्येक Visitors के लिए एक Unique Number बन कर और इस की Id के आधार पर Storage के लिए काम करता है. Session एक ही Webpage पर जाने के दौरान दो User के Data को एक दूसरे के साथ confused होने से रोकने में भी Help करता है.

PHP Session को शुरू करने के लिये session_start() function से Call करते है यह Function पहले Check करता है कि कोई Session पहले से शुरू हे कि नही अगर कोई पहले शुरू नही हुआ तो ये एक Session को शुरू कर देता है.

For Example

<?php
// PHP session start
session_start();
?>
<!DOCTYPE html>
<html>
   <head>
      <title>PHP session start</title>
   </head>
   <body>
      <?php  
        if($userid != '')
        {
            echo "User session is started.";
        }
        else
        {
            echo "User session is not started.";
        }
      ?>
   </body>
</html>

Output

User session is not started.

Destroy a PHP Session

सभी Global Session Variables को Remove करने और Session को Destroy करने के लिए session_unset () और session_destroy () का उपयोग करते है.

For Example

<?php
   session_start();
   
   if (isset($_SESSION['counter'])) {
      $_SESSION['counter']++;
   } else {
      $_SESSION['counter'] = 1; 
   }

   
   $msg = "You have visited this page ".  $_SESSION['counter'];
   $msg .= "in this session.";
   
   echo ( $msg );
?>

<p>
   To continue  click following link <br />
   
   <a  href = "nextpage.php?<?php echo htmlspecialchars(SID); ?>">
</p>

Output

You have visited this page 4in this session.
To continue click following link

PHP in Hindi Cookies

Cookie एक Small Text File है जो उपयोगकर्ता को Computer पर Small Quantity में Data को Store करती है. इसको आम तौर पर Username जैसे जानकारी का Track रखने के लिए उपयोग किया जाता है. PHP के साथ आप Cookie Value को Create और Retrieve कर सकते हैं.

Setting Cookies

Setcookie() Function को PHP में Cookie सेट करने के लिए उपयोग किया जाता है.

<?php
   setcookie("username", "raja", time()+3600, "/","", 0);
   setcookie("name", "Waseem", time()+3600, "/", "",  0);
?>

Accessing Cookies

PHP Cookies Access करने के कई तरीके प्रदान करता है लेकिन सबसे आसान तरीका $ _COOKIE और $ HTTP_COOKIE_VARS Variables का उपयोग करके हम Cookies को Access कर सकते है.

<!DOCTYPE html>
<html>
   <head>
      <title>Accessing Cookies Example</title>
   </head>
   <body>
      <?php
         echo $_COOKIE["name"]. "<br />";
         
         /* is equivalent to */
         echo $HTTP_COOKIE_VARS["name"]. "<br />";
         
         echo $_COOKIE["age"] . "<br />";
         
         /* is equivalent to */
         echo $HTTP_COOKIE_VARS["age"] . "<br />";         
      ?>     
   </body>
</html>

Output

Deleting Cookies

किसी भी Cookies को Delete करने के लिए आपको Cookies को उस Date से सेट करना होगा जो पहले से ही Setcookie () Function में Delete हो गई हो.

<?php
   setcookie("username", "raja", time()-3600, "/","", 0);
   setcookie("name", "Waseem", time()-3600, "/", "",  0);
?>

PHP in Hindi Arrays

Arrays एक Complex Variables है जो हमें एक से अधिक Value को Single Variable के Name से Store करने की अनुमति देता हैं.

Arrays के उपयोग से Data को Quick और कुशलता अनुसार Stored करना आसन होता है. यह किसी भी Programming Language के लिए उपलब्ध अधिक उपयोगी Data Types मे से एक है.

Arrays Elements की Sorted List मे आसानी से Described किया जा सकता है. आप Array के भीतर उनकी Index Event का Reference देकर अलग-अलग Elements तक आसानी से पहुंच सकते हो.

PHP मे सभी Array Supporting होते है लेकिन आप उन तक पहुंचने के लिए एक Numerical Index का उपयोग कर सकते है. Numerical Index के साथ एक Array को आमतौर पर एक Indexed Array भी कहा जाता है.

Arrays अलग-अलग 3 Type के होते है और हर एक Arrays की Value को ID C का उपयोग करते हुए Accessed किया जाता है.

  • Indexed Array

  • Associative Array

  • Multidimensional Array

Indexed Array

Indexed Array को Number से Represent करते है जो 0 से शुरू होता है. हम PHP Array में String, Number और Object को इकट्ठा कर सकते हैं.

For Example

<!DOCTYPE html>
<html>
   <head>
      <title>Indexed Array Example</title>
   </head>
   <body>
      <?php
         // Indexed Arrays Example  //
      
         $num_array = array( 1, 2, 3, 4, 5);
         
         foreach( $num_array as $val)
         {
            echo "Array value is $val <br />";
         }
      
         // store with index value
         $num_array[0] = "one";
         $num_array[1] = "two";
         $num_array[2] = "three";
         $num_array[3] = "four";
         $num_array[4] = "five";
      
         foreach( $num_array as $val)
         {
            echo "Array value is $val <br />";
         }        
      ?>
   </body>
</html>

Output

Array value is 1
Array value is 2
Array value is 3
Array value is 4
Array value is 5
Array value is one
Array value is two
Array value is three
Array value is four
Array value is five

Associative Array

Associative Array Functionality की Term में Numeric Arrays के समान होता है. लेकिन वे अपने Index Number के मामले में थोड़ा अलग हैं. Associative Array को अपने Index को String के रूप में रखना होता है जिससे Index ताकि अपने Key और Value के बीच Strong Connection को कायम कर सके.

For Example

<!DOCTYPE html>
<html>   
   <head>
      <title>Associative Arrays Example</title>
   </head>   
   <body>     
      <?php
      // Associative Arrays Example  //
      
      $marks = array("raja" => 995, "waseem" => 770, "rani" => 855);
         
      echo "Total Marks gain by raja is ". $marks ['raja'] . "<br/>";
      echo "Total Marks gain by waseem is ". $marks ['waseem'] . "<br/>";
      echo "Total Marks gain by rani is ". $marks ['sita'] . "<br/>";
      
      /* Another method to store data in associative arrays */
      $ranks['raja'] = "First";
      $ranks['waseem'] = "Second";
      $ranks['rani'] = "Third";
      
      echo "Rank of raja is ". $ranks['raja'] . "<br/>";
      echo "Rank of waseem is ".  $ranks['waseem']. "<br/>";
      echo "Rank of rani is ".  $ranks['rani']. "<br/>";   
   ?>     
   </body>

Output

Total Marks gain by raja is 995
Total Marks gain by waseem is 770
Total Marks gain by rani is
Rank of raja is First
Rank of waseem is Second
Rank of rani is Third

Multidimensional Array

Multidimensional Array एक Array में जिसमें प्रत्येक Element भी Array होते है और इसी तरह Multidimensional Array की Value को एक से अधिक Index मे उपयोग किया जाता है.

For Example

<!DOCTYPE html>
<html>   
   <head>
      <title>Multidimensional Array Example</title>
   </head>   
   <body>     
      <?php
      // Multidimensional Arrays Example //
      
      $marks = array( 
         "raja" => array
         (
            "physics" => 95,
            "maths" => 86,	
            "chemistry" => 75
         ),
         
         "waseem" => array
         (
            "physics" => 80,
            "maths" => 72,
            "chemistry" => 79
         ),
         
         "rani" => array
         (
            "physics" => 71,
            "maths" => 97,
            "chemistry" => 84
         )
      );
         
        
      echo "Marks for raja in physics : " ;
      echo $marks['raja']['physics'] . "<br/>"; 
      
      echo "Marks for waseem in maths : ";
      echo $marks['waseem']['maths'] . "<br/>"; 
      
      echo "Marks for rani in chemistry : " ;
      echo $marks['rani']['chemistry'] . "<br/>";
   ?>
   </body>
</html>

Output

Marks for raja in physics : 95
Marks for waseem in maths : 72
Marks for rani in chemistry : 84

PHP in Hindi Loop Types

Loop का उपयोग बार-बार Code के एक ही Block को Execute करने के लिए किया जाता है जब तक Condition पूरी न हो जाए. समय और प्रयास को बचाने के लिए एक Program के भीतर दोहराए जाने वाले कार्य को Automatic Repetitive करने के लिये हम Loop चलाते है.

PHP 4 Type के Loop को Support करती है.

  • While Loop

  • Do...while Loop

  • For Loop

  • Foreach Loop

While Loop

while Loop Code के एक Block को Executes करता रहता है जब तक कि Specified Condition True नहीं हो जाती है.

Syntax

while (condition)
{
  code that will be executed;
}

For Example

<!DOCTYPE html>
<html>
   <head>
      <title>While Loop Example</title>
   </head>
   <body>
      <?php
         $i = 5;   
         while( $i < 20 )
         {
            echo $i."<br/>";
            $i++;
         }
         echo "After while loop i value is $i";         
      ?>
   </body>
</html>

Output

5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
After while loop i value is 20

Do...While Loop

do...While Loop हमेशा एक बार Code के Block को Execute करता है और तब यह Condition को Check करता है और Condition True होने तक Loop को दोहराता है.

Syntax

do
{
   code to be executed;
}
while (condition);

For Example

<!DOCTYPE html>
<html>   
   <head>
      <title>Do While Loop Example</title>
   </head>   
   <body>     
      <?php
         $i = 0;   
         do
         {
            echo $i."<br/>";
            $i++;
         }
         while($i < 10);
         echo "After loop i value is $i";           
      ?>  
   </body>
</html>

Output

0
1
2
3
4
5
6
7
8
9
After loop i value is 10

For Loop

For Loop का उपयोग विशिष्ट समय के लिए Code Set करने के लिए किया जा सकता है. जब आप पहले से जानते हैं कि Script कितनी बार चलनी चाहिए .

Syntax

for (init; condition; increment)
{
   code to be executed;
}

For Example

<!DOCTYPE html>
<html>   
   <head>
      <title>For Loop Example</title>
   </head>   
   <body>     
      <?php
         for( $i = 10; $i < 20; $i++ )
         {
            echo $i."<br/>";
         }
         echo "After for loop i value is $i"; 
      ?>
   </body>
</html>

Output

10
11
12
13
14
15
16
17
18
19
After for loop i value is 20

Foreach Loop

Foreach Loop केवल Arrays पर काम करता है और Array में सब key-value समरूप के माध्यम से Loop के लिए उपयोग किया जाता है.

Syntax

foreach ($array as $value)
{
   code to be executed;
}

For Example

<!DOCTYPE html>
<html>   
   <head>
      <title>Foreach Loop Example</title>
   </head>   
   <body>     
      <?php
         $array = array( 1, 2, 3, 4, 5);
         
         foreach( $array as $value ) {
            echo "Value is $value <br />";
         }
      ?>
   </body>
</html>

Output

Value is 1
Value is 2
Value is 3
Value is 4
Value is 5

PHP in Hindi Decision Making

PHP मे Decision Making Statements विभिन्न कार्यों के आधार पर विभिन्न प्रकार के कार्यों को करने के लिए उपयोग किया जाता है. इसमे if, elseif ...else और Switch Statements का उपयोग अलग Condition मे Decision Making के लिए किया जाता है. आप अपने Decision लेने के लिए Code में Conditional Statements का उपयोग कर सकते हैं.

PHP Three Decision Making Statements को Supports करता है.

  • if...else statement

  • elseif statement

  • switch statement

If...Else Statement

If...Else Statement कुछ Code को Executes करता है यदि कोई Condition True है और दूसरे Code मे अगर वह Condition False है तो हम if...else Statement का उपयोग करते है.

<!DOCTYPE html>
<html>
   <head>
      <title>If...Else Statement Example</title>
   </head>
   <body>
      <?php
         $d = date("D");
         
         if ($d == "Fri")
            echo "Have a nice weekend!"; 
         
         else
            echo "Have a nice day!";         
      ?>
   </body>
</html>

Output

Have a nice day!

ElseIf Statement

अगर आप कुछ Code को Executes करना चाहते हैं और कई Conditions में से एक सही है तो आप elseif Statement का उपयोग कर सकते है.

<!DOCTYPE html>
<html>   
   <head>
      <title>ElseIf Statement Example</title>
   </head>   
   <body>     
      <?php
		
      // ElseIf Statement Example //
      
      $d = date("D");
         
         if ($d == "Fri")
            echo "Have a nice weekend!";
         
         elseif ($d == "Sun")
            echo "Have a nice Sunday!"; 
         
         else
            echo "Have a nice day!";           
   ?>  
   </body>
</html>

Output

Have a nice day!

Switch Statement

Switch Statement का उपयोग Execute किये जाने वाले Code के कई Block को Select करने के लिए किया जाता है.

<!DOCTYPE html>
<html>   
   <head>
      <title>Switch Statement Example</title>
   </head>   
   <body>     
      <?php
         $d = date("D");
         
         switch ($d){
            case "Mon":
               echo "Today is Monday";
               break;
            
            case "Tue":
               echo "Today is Tuesday";
               break;
            
            case "Wed":
               echo "Today is Wednesday";
               break;
            
            case "Thu":
               echo "Today is Thursday";
               break;
            
            case "Fri":
               echo "Today is Friday";
               break;
            
            case "Sat":
               echo "Today is Saturday";
               break;
            
            case "Sun":
               echo "Today is Sunday";
               break;
            
            default:
               echo "Wonder which day is this ?";
         } 
   ?>
   </body>
</html>

Output

Today is Saturday

PHP in Hindi File Uploading

PHP Script का प्रयोग एक HTML Form के साथ किया जा सकता है जिससे उपयोगकर्ता को Server पर File Upload करने की अनुमति मिल सके. Initially Files को Temporary Directory में Upload किया जाता है और फिर एक PHP Script द्वारा Destination पर Transfer किया जाता है.

<!DOCTYPE html>
<html lang="en">
<?php
   if(isset($_FILES['fileImg'])){
      $errors= array();
      $fname = $_FILES['fileImg']['name'];
      $fsize =$_FILES['fileImg']['size'];
      $tmp_file =$_FILES['fileImg']['tmp_name'];
      $file_type=$_FILES['fileImg']['type'];
      $file_ext=strtolower(end(explode('.',$_FILES['fileImg']['name'])));
      
      $expensions= array("jpeg","jpg","png");
      
      if(in_array($file_ext,$expensions)=== false){
         $errors[]="Please select a JPEG or PNG file only!";
      }
      
      if($fsize > 2097152){
         $errors[]='Max file size allowed is 2 MB only!';
		}
      
      if(empty($errors)==true){
         move_uploaded_file($tmp_file,"images/".$fname);
         echo "Success";
      }
      else{
         print_r($errors);
      }
   }
?>
<html>
   <head>
      <title>PHP File Uploading Example</title>
   </head>
   <body>      
      <form action="" method="POST" enctype="multipart/form-data">
         <input type="file" name="fileImg" />
         <input type="submit" value="Upload" />
			
      </form>
      <?php
          if(isset($_FILES['fileImg']['name'])){
             echo "Upload File Details";
         ?>
         <ul>
            <li>Sent file: <?php echo $_FILES['fileImg']['name'];  ?>
            <li>File size: <?php echo $_FILES['fileImg']['size'];  ?>
            <li>File type: <?php echo $_FILES['fileImg']['type'] ?>
         </ul>
         <?php
          }
         ?>
   </body>
</html>

Output

PHP File Uploading Example

PHP in Hindi File I/O

इस chapter मे हम File Input Output के बारे मे चर्चा करेंगे कि केसे PHP मे File को Open, Read, Write और Close कर सकते है.

  • Opening a File

  • Reading a File

  • Writing a File

  • Closing a File

Opening a File

PHP मे File को Open करने के लिये fopen() Function का उपयोग करते है. इस Function के लिए Two Arguments होते है जो पहले File का नाम बताते हैं फिर उस Mode में Opreate होते हैं.

Opening File मे यह Six File Modes : r , r+ , w , w+ , a , a+ होते है

Reading a File

एक बार File को fopen() Function का उपयोग करके खोला जाता है इसे fread() नामक Function से Read किया जा सकता है. इस Function मे दो Arguments की आवश्यकता होती है और ये File Pointer और bytes मे File expressed की length के होना चाहिए.

Files की Length Files filesize() Function का उपयोग करके कम की जा सकती है जो File Name को अपनी तर्क के रूप में लेती है और Bytes मे व्यक्त File का Size देती है.

For Example

<!DOCTYPE html>
<html>
   <head>
      <title>Reading a File Example</title>
   </head>
   <body>
      <?php
         $filename = "temp_file.txt";
         $filepoint = fopen( $filename, "r" );
         
         if( $filepoint == false )
         {
            echo ( "Error in opening file" );
            exit();
         }
         
         $filesize = filesize( $filename );
         $filetext = fread( $filepoint, $filesize );
         fclose( $filepoint );
         
         echo ( " The following is the content of the file <br/> " );
         echo ( " <pre> $filetext </pre> " );         
      ?>
   </body>
</html>

Output

Error in opening File

Writing a File

PHP मे fwrite() Function का उपयोग करके एक New File को Write किया जा सकता है या किसी मौजूदा File मे Text को जोड़ा जा सकता है. इस Function को दो Arguments को एक File Pointer और Data के String को Specify करने की आवश्यकता होती है जिससे यह Write किया जाता है. वैकल्पिक रूप से एक तीसरी Integer Argument को लिखने के लिए Data की Length को Specify करने के लिए शामिल किया जा सकता है. यदि तीसरा Argument शामिल है तो Specify Length तक पहुंचने के बाद Writing बंद हो जायगी. File को Close करने के बाद file_exist() Function का उपयोग कर इसकी मौजूदगी की पुष्टि होती है जो Argument के रूप मे File नाम लेती है.

For Example

<?php
   $filename = "newfile.txt";
   $filepoint = fopen( $filename, "w" );   
   if( $filepoint == false )
   {
      echo ( "Error in opening new file" );
      exit();
   }
   fwrite( $filepoint, "The new file create and write text.\n" );
   fclose( $filepoint );
?>
<html>   
   <head>
      <title>Writing a file Example</title>
   </head>   
   <body>      
      <?php
         $filename = "newfile.txt";
         $filepoint = fopen( $filename, "r" );         
         if( $filepoint == false )
         {
            echo ( "Error in opening file" );
            exit();
         }
         
         $filesize = filesize( $filename );
         $filetext = fread( $filepoint, $filesize );
         
         fclose( $filepoint);
         
         echo ( " Total File size : $filesize bytes <br/> " );
         echo ( " Text in the file:: <br/> " );
         echo ( "  $filetext " );         
      ?>      
   </body>
</html>

Output

Total File size : 36 bytes
Text in the file::
The new file create and write text.

Closing a File

PHP मे File को Close करने के लिये fclose() Function का उपयोग करते है.

For Example

<!DOCTYPE html> 
<html>   
   <head>
      <title>Closing a File Example</title>
   </head>   
   <body>      
      <?php
         echo "<p>Opening the File <b>tutorialsroot.txt</b> .....</p>";
         $myfile = fopen("tutorialsroot.txt", "r");
         if($myfile == false)
         {
            echo "Error occurred...exiting...";
            exit();
         }
         echo "<p>File opened successfully.</p>";
         echo "<p>Closing the File....</p>";
         fclose($myfile);
         echo "<p>File closed successfully.</p>"         
      ?>      
   </body>
</html>

Output

Opening the File tutorialsroot.txt .....
Error occurred...exiting...

PHP in Hindi File I/O

इस Chapter मे हम File Input Output के बारे मे चर्चा करेंगे कि केसे PHP मे File को Open, Read, Write और Close कर सकते है.

  • Opening a File

  • Reading a File

  • Writing a File

  • Closing a File

Opening a File

PHP मे File को open करने के लिये fopen() Function का उपयोग करते है. इस Function के लिए Two Arguments होते है जो पहले File का नाम बताते हैं फिर उस Mode में Opreate होते हैं.

Opening File मे यह Six File modes : r , r+ , w , w+ , a , a+ होते है.

Reading a File

एक बार File को fopen() Function का उपयोग करके खोला जाता है इसे fread() नामक Function से Read किया जा सकता है. इस Function मे दो Arguments की आवश्यकता होती है और ये File Pointer और Bytes मे File Expressed की Length के होना चाहिए.

Files की Length Files Filesize() Function का उपयोग करके पाई जा सकती है जो File Name को अपनी तर्क के रूप में लेती है और Bytes मे व्यक्त File का Size देती है.

For Example

<!DOCTYPE html>
<html>
   <head>
      <title>Reading a File Example</title>
   </head>
   <body>
      <?php
         $filename = "temp_file.txt";
         $filepoint = fopen( $filename, "r" );
         
         if( $filepoint == false )
         {
            echo ( "Error in opening file" );
            exit();
         }
         
         $filesize = filesize( $filename );
         $filetext = fread( $filepoint, $filesize );
         fclose( $filepoint );
         
         echo ( " The following is the content of the file <br/> " );
         echo ( " <pre> $filetext </pre> " );         
      ?>
   </body>
</html>

Output

Writing a File

PHP मे fwrite() Function का उपयोग करके एक New File को write किया जा सकता है या किसी मौजूदा File मे Text को जोड़ा जा सकता है. इस Function को दो Arguments को एक File Pointer और Data के String को Specify करने की आवश्यकता होती है जिससे यह Write किया जाता है.

वैकल्पिक रूप से एक तीसरी Integer Argument को लिखने के लिए Data की Length को Specify करने के लिए शामिल किया जा सकता है. यदि तीसरा Argument शामिल है तो Specify Length तक पहुंचने के बाद Writing बंद हो जायगी. File को Close करने के बाद file_exist() Function का उपयोग कर इसकी मौजूदगी की पुष्टि होती है जो Argument के रूप मे File नाम लेती है.

For Example

<?php
   $filename = "newfile.txt";
   $filepoint = fopen( $filename, "w" );   
   if( $filepoint == false )
   {
      echo ( "Error in opening new file" );
      exit();
   }
   fwrite( $filepoint, "The new file create and write text.\n" );
   fclose( $filepoint );
?>
<html>   
   <head>
      <title>Writing a file Example</title>
   </head>   
   <body>      
      <?php
         $filename = "newfile.txt";
         $filepoint = fopen( $filename, "r" );         
         if( $filepoint == false )
         {
            echo ( "Error in opening file" );
            exit();
         }
         
         $filesize = filesize( $filename );
         $filetext = fread( $filepoint, $filesize );
         
         fclose( $filepoint);
         
         echo ( " Total File size : $filesize bytes <br/> " );
         echo ( " Text in the file:: <br/> " );
         echo ( "  $filetext " );         
      ?>      
   </body>
</html>

Output

Closing a File

PHP मे File को Close करने के लिये fclose() Function का उपयोग करते है.

For Example

<!DOCTYPE html> 
<html>   
   <head>
      <title>Closing a file Example</title>
   </head>   
   <body>      
      <?php
         echo "<p>Opening the file <b>tutorialsroot.txt</b> .....</p>";
         $myfile = fopen("tutorialsroot.txt", "r");
         if($myfile == false)
         {
            echo "Error occurred...exiting...";
            exit();
         }
         echo "<p>File opened successfully.</p>";
         echo "<p>Closing the file....</p>";
         fclose($myfile);
         echo "<p>File closed successfully.</p>"         
      ?>      
   </body>
</html>

Output