About

Breaking

Wednesday 24 May 2017

PHP - Syntax Overview

This chapter will give you an idea of very basic syntax of PHP and very important to make your PHP foundation strong.

Escaping to PHP

The PHP parsing engine needs a way to differentiate PHP code from other elements in the page. The mechanism for doing so is known as 'escaping to PHP'. There are four ways to do this

यह अध्याय आपको PHP के बहुत ही बुनियादी सिंटैक्स का विचार देगा और आपके PHP आधार को मजबूत बनाने के लिए महत्वपूर्ण होगा।

PHP से बचें
 
पीएचपी पार्सिंग इंजन को पृष्ठ में अन्य तत्वों से पीएचपी कोड को अलग करने का एक तरीका चाहिए। ऐसा करने के लिए तंत्र को 'पीएपी से बचने' के रूप में जाना जाता है ऐसा करने के चार तरीके हैं


Canonical PHP tags

The most universally effective PHP tag style is −

कैनोनिकल पीएचपी टैग

सबसे सार्वभौमिक प्रभावी PHP टैग शैली है - 
<?php...?>

If you use this style, you can be positive that your tags will always be correctly interpreted.

Short-open (SGML-style) tags

Short or short-open tags look like this −

यदि आप इस शैली का उपयोग करते हैं, तो आप सकारात्मक हो सकते हैं कि आपके टैग हमेशा सही तरीके से व्याख्या किए जाएंगे।

लघु-खुले (एसजीएमएल-शैली) टैग

लघु या लघु-खुले टैग इस तरह दिखते हैं -
<?...?>

Short tags are, as one might expect, the shortest option You must do one of two things to enable PHP to recognize the tags −
  • Choose the --enable-short-tags configuration option when you're building PHP.
  • Set the short_open_tag setting in your php.ini file to on. This option must be disabled to parse XML with PHP because the same syntax is used for XML tags.

ASP-style tags

ASP-style tags mimic the tags used by Active Server Pages to delineate code blocks. ASP-style tags look like this −

लघु टैग, जैसा कि एक उम्मीद कर सकता है, कम से कम विकल्प आपको PHP को टैग पहचानने के लिए सक्षम करने के लिए दो चीजों में से एक करना होगा -

जब आप पीएचपी का निर्माण कर रहे हैं तो --सक्षम- short-tags विन्यास विकल्प चुनें

अपनी php.ini फ़ाइल में short_open_tag सेटिंग को ऑन पर सेट करें। यह विकल्प PHP के साथ XML को पार्स करने के लिए अक्षम होना चाहिए क्योंकि एक्सएमएल टैग के लिए एक ही वाक्यविन्यास उपयोग किया जाता है।

एएसपी-शैली टैग

एएसपी-स्टाइल टैग कोड ब्लॉक को चित्रित करने के लिए सक्रिय सर्वर पेजों द्वारा उपयोग किए गए टैग की नकल करते हैं। एएसपी-शैली टैग इस तरह दिखते हैं -
<%...%>
 

To use ASP-style tags, you will need to set the configuration option in your php.ini file.

HTML script tags

HTML script tags look like this −

एएसपी-शैली टैग का उपयोग करने के लिए, आपको अपने php.ini फ़ाइल में कॉन्फ़िगरेशन विकल्प सेट करना होगा।

एचटीएमएल स्क्रिप्ट टैग
एचटीएमएल स्क्रिप्ट टैग इस तरह दिखते हैं -

<script language="PHP">...</script>


Commenting PHP Code

A comment is the portion of a program that exists only for the human reader and stripped out before displaying the programs result. There are two commenting formats in PHP −
Single-line comments − They are generally used for short explanations or notes relevant to the local code. Here are the examples of single line comments.

 PHP कोड टिप्पणी

एक टिप्पणी एक ऐसे प्रोग्राम का हिस्सा है जो केवल मानव पाठक के लिए मौजूद है और प्रोग्राम परिणाम प्रदर्शित करने से पहले छीन ली गई है। PHP में दो टिप्पणी प्रारूप हैं -

सिंगल-लाइन टिप्पणियां - आमतौर पर स्थानीय कोड से संबंधित संक्षिप्त स्पष्टीकरण या नोट्स के लिए इसका उपयोग किया जाता है। यहां एकल पंक्ति टिप्पणियों के उदाहरण दिए गए हैं।




<?
   # This is a comment, and
   # This is the second line of the comment
  
   // This is a comment too. Each style comments only
   print "An example with single line comments";
?>

 

PHP is whitespace insensitive

Whitespace is the stuff you type that is typically invisible on the screen, including spaces, tabs, and carriage returns (end-of-line characters).
PHP whitespace insensitive means that it almost never matters how many whitespace characters you have in a row.one whitespace character is the same as many such characters.
For example, each of the following PHP statements that assigns the sum of 2 + 2 to the variable $four is equivalent −

पीएचपी अस्थिर है

व्हाइटस्पेस आपके द्वारा टाइप की जाने वाली सामग्री है, जो स्क्रीन पर विशेष रूप से अदृश्य है, जिसमें रिक्त स्थान, टैब, और कैरिज रिटर्न (अंत-लाइन-वर्ण) शामिल हैं।

PHP श्वेतस्थान असंवेदनशील मतलब है कि यह लगभग कभी नहीं मानता है कि आपके पास पंक्ति में कितने श्वेत स्थान के अक्षर हैं.एक सफेद श्वेत स्थान चरित्र उतना ही ऐसे वर्णों के समान है।

उदाहरण के लिए, निम्न में से प्रत्येक PHP स्टेटमेंट जो $ 4 के चर के लिए 2 + 2 की राशि समनुरूप है -


$four = 2 + 2; // single spaces
$four <tab>=<tab2<tab>+<tab>2 ; // spaces and tabs
$four =
2+
2; // multiple lines



PHP is case sensitive

Yeah it is true that PHP is a case sensitive language. Try out following example −

PHP केस संवेदनशील है

हाँ यह सच है कि PHP एक केस संवेदनशील भाषा है। निम्नलिखित उदाहरण देखें -

<html>
   <body>
     
      <?php
         $capital = 67;
         print("Variable capital is $capital<br>");
         print("Variable CaPiTaL is $CaPiTaL<br>");
      ?>
     
   </body>
</html>


 
This will produce the following result −

Variable capital is 67
Variable CaPiTaL is


Statements are expressions terminated by semicolons

A statement in PHP is any expression that is followed by a semicolon (;).Any sequence of valid PHP statements that is enclosed by the PHP tags is a valid PHP program. Here is a typical statement in PHP, which in this case assigns a string of characters to a variable called $greeting −
 वक्तव्य अभिव्यक्ति अर्धविराम द्वारा समाप्त कर दिए गए हैं
 
PHP में दिए गए एक बयान किसी भी अभिव्यक्ति है जो एक अर्धविराम (;) के द्वारा पीछा किया जाता है। PHP टैग्स से जुड़े वैध PHP वक्तव्य के किसी भी अनुक्रम एक वैध PHP प्रोग्राम है। यहां PHP में एक विशिष्ट बयान दिया गया है, जो इस मामले में $ ग्रीटिंग नामक एक चर के लिए अक्षर की एक स्ट्रिंग प्रदान करता है -
$greeting = "Welcome to PHP!";



Expressions are combinations of tokens

The smallest building blocks of PHP are the indivisible tokens, such as numbers (3.14159), strings (.two.), variables ($two), constants (TRUE), and the special words that make up the syntax of PHP itself like if, else, while, for and so forth

Braces make blocks

Although statements cannot be combined like expressions, you can always put a sequence of statements anywhere a statement can go by enclosing them in a set of curly braces.
Here both statements are equivalent −
 अभिव्यक्तियां टोकन के संयोजन हैं
पीएचपी की सबसे छोटी बिल्डिंग ब्लॉकों अविभाज्य टोकन हैं, जैसे कि नंबर (3.1415 9), स्ट्रिंग (दो।), वेरिएबल्स ($ 2), स्थिर (TRUE), और विशेष शब्द जो कि PHP की सिंटैक्स बनाते हैं जैसे कि , और, जबकि, के लिए और इतने आगे

ब्रेसिंग ब्लॉक बनाते हैं
यद्यपि बयान अभिव्यक्ति की तरह नहीं जोड़ा जा सकता है, आप हमेशा कथन के अनुक्रम के रूप में कहीं भी एक कथन को जोड़कर किसी बयान को जोड़ सकते हैं।

यहाँ दोनों बयान समतुल्य हैं -

if (3 == 2 + 1)
   print("Good - I haven't totally lost my mind.<br>");
  
if (3 == 2 + 1) {
   print("Good - I haven't totally");
   print("lost my mind.<br>");
}


Running PHP Script from Command Prompt

Yes you can run your PHP script on your command prompt. Assuming you have following content in test.php file
कमांड प्रॉम्प्ट से PHP स्क्रिप्ट चलाना

हाँ, आप अपने कमांड प्रॉम्प्ट पर अपनी PHP स्क्रिप्ट चला सकते हैं। यह मानते हुए कि आपने test.php फ़ाइल में सामग्री का पालन किया है

<?php
   echo "Hello PHP!!!!!";
?>


 Now run this script as command prompt as follows −
 अब इस स्क्रिप्ट को कमांड प्रॉम्प्ट के रूप में निम्नानुसार चलाएं -

$ php test.php

It will produce the following result −
यह निम्न परिणाम उत्पन्न करेगा -  

Hello PHP!!!!!


 Hope now you have basic knowledge of PHP Syntax.
आशा है कि आपके पास PHP सिंटैक्स का बुनियादी ज्ञान है 

4 comments: