php strings

php strings

Strings character का sequence यानि की समूह (group) है||

string declaration

string तीन तरीके से declare कर सकते है||

  • single quoted
  • double quoted
  • doc syntax
    • nowdoc => यह single quoted की तरह काम करता है||
    • heredoc => यह double quoted की तरह काम करता है||

Single quoted

single quoted में, string को single quoted में declared किया जाता है| single quoted character: ‘ ‘

<?php
  $string = 'Hello this is my first single quoted strings';
  echo $string;
?>

output

Hello this is my first single quoted strings

अगर हम single quoted string में another single quoted को add करना चाहते है तो back slash character के साथ add कर सकते है|

<?php
  $string = 'Hello this is my first strings it\'s very good';
  echo $string; 
?>

output

Hello this is my first string it’s very good

Double quoted

double quoted में, string को double quoted में declared किया जाता है| double quoted character: ” “

<?php
  $string = "Hello this is my first double quoted strings";
  echo $string;
?>

output

Hello this is my first double quoted strings

single quoted के मुकाबले double quoted में कई सारे escape sequence है|

Escape sequenceDescription
\”double quoted
\nline break
\ttab space
\rcarriage return
\\backslash
\$dollar sign

Doc syntax

Doc syntax में string को अलग way में declared किया जा सकता है जिसमे दो प्रकार है 1) heredoc 2) nowdoc और वह single और double quoted की तरह काम करते है||
Doc syntax <<<IDENTIFIERTOKEN characters के साथ start होता है| और IDENTIFIERTOKEN के साथ close होता है|
और उसके बाद identifier token को <<< के साथ एक ही line में single और double qouted में लिखा जाता है|

syntax:

$data = <<<IDENTIFIERTOKEN
IDENTIFIERTOKEN;

Nowdoc

Nowdoc यह similar single quoted के तरह work करता है|

<?php
$string =<<<'STRING'
welcome to RjtechyG <br>
it is very helful for the beginners<br>
it is also have "hindi" contant<br>
this is nowdoc synax.
STRING;
echo $string;
?>

output

welcome to RjtechyG
it is very helful for the beginners
it is also have “hindi” contant
this is nowdoc synax.

heredoc

heredoc यह similar double quoted के तरह work करता है| heredoc में token को double quoted में लिखने की जरुरत नहीं होती है|

<?php
$string =<<<STRING
Welcome to RjtechyG
it is very helpful for the beginners
it also has "Hindi" content
this is heredoc syntax.
STRING;
echo $string;
?> 

output

Welcome to RjtechyG
it is very helpful for the beginners
it also has “Hindi” content
this is heredoc syntax.

Leave a Comment

Your email address will not be published. Required fields are marked *