← Back to PHP Course | Chapter 1: Introduction & Basics | Lesson 1 of 13

PHP का Introduction

PHP एक ऐसी language है जो website के computer पर रहती है और page को on the spot बनाती है, जैसे कोई cook जब customer order करे तब ही खाना ताज़ा बनाता है। Visitors को सिर्फ finished page दिखता है, recipe कभी नहीं।

PHP क्या है?

PHP का मतलब है 'PHP: Hypertext Preprocessor' (एक recursive acronym), web के लिए purpose-built एक open-source scripting language।

एक general-purpose language को server पर bolt करने के उलट, PHP शुरू से ही HTML generate करने और databases से बात करने के लिए design की गई थी, इसीलिए यह आज भी web के backend code के एक बड़े हिस्से का engine है।

उदाहरण: What is PHP?

php
<?php
// PHP: Hypertext Preprocessor -- generates HTML and talks to databases
echo "Hello from the server-side!";
?>

PHP क्यों सीखें?

PHP approachable है क्योंकि आप इसे सीधे HTML में mix कर सकते हैं और तुरंत results देख सकते हैं, बिना किसी compile step या भारी project scaffolding के।

यह typical web workloads के लिए genuinely fast भी है और उन चीज़ों के लिए built-in functions रखता है जो web apps लगातार करते हैं: input sanitize करना, passwords hash करना, और databases से बात करना।

उदाहरण: Why Learn PHP?

php
<!DOCTYPE html>
<html>
<body>
<h1>Mixing PHP directly into HTML</h1>
<?php // date() below runs on the server before the page is sent to the browser ?>
<p>Generated at: <?php echo date("H:i:s"); ?></p>
</body>
</html>

PHP कैसे काम करता है

PHP एक server-side language है, यानी .php file visitor के browser तक कभी नहीं पहुँचती।

Web server PHP code चलाता है, PHP plain HTML (या JSON, या आप जो भी text output चुनें) produce करता है, और सिर्फ वही output browser को भेजा जाता है — visitor 'View Page Source' से आपका PHP source नहीं देख सकता।

उदाहरण: How PHP Works

php
<?php
// This code runs on the server; the browser only ever sees the output below
$name = "Guest";
echo "<p>Welcome, " . $name . "</p>";
?>

PHP के Applications

क्योंकि PHP page browser तक पहुँचने से पहले चलता है, यह वे चीज़ें कर सकता है जो सिर्फ browser वाली language नहीं कर सकती: server पर files पढ़ना और लिखना, एक database query करना, session state check करना, और page का content dynamically assemble करना इस आधार पर कि कौन request कर रहा है और उसने क्या submit किया।

उदाहरण: Applications of PHP

php
<?php
// PHP can read/write files, unlike a browser-only language
file_put_contents('visits.txt', "Visitor logged\n", FILE_APPEND);
echo "Visit recorded on the server.";
?>

PHP के Benefits

PHP Windows, Linux, और macOS पर चलता है, और हर major web host और cloud provider इसे out of the box support करता है, जो इसके इतना widely deployed रहने की एक बड़ी वजह है — आपको PHP काम करवाने के लिए शायद ही कभी अपने hosting environment से लड़ना पड़ता है।

उदाहरण: Benefits of PHP

php
<?php
// Print "PHP_OS: " . PHP_OS . "\n" to the output
echo "PHP_OS: " . PHP_OS . "\n";
// Print "This same script runs unmodified on Windows, Linux, or macOS." to the output
echo "This same script runs unmodified on Windows, Linux, or macOS.";
?>
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. Browser में file system से सीधे एक .php file खोलना (file:///...), जो raw source दिखाता है क्योंकि PHP सिर्फ तभी चलता है जब कोई server या CLI file को interpret करे।
  2. यह मानना कि visitors browser में आपका PHP code देख सकते हैं, फिर गलत जगह पर secrets hard-code करना; server PHP चलाता है और सिर्फ उसका output भेजता है, लेकिन एक misconfigured server अभी भी source files expose कर सकता है।
  3. एक page को .html extension के साथ save करना और <?php ... ?> के चलने की उम्मीद करना, जबकि server default रूप से सिर्फ .php files PHP interpreter को सौंपता है।

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.