-->

  • php String single vs double quotes





    PHP STRING SINGLE VS DOUBLE QUOTES 

    PHP string single vs double quotes learn befora that we will learn about string. What is String ?
    A string is sequence of characters like "Kumar Atul Jaiswal" or "Hello world" Etc i.e. used to store and manipulate text.



    For more information Click Here  :- String 


    There are four ways to specify string in PHP.

    • Single syntax
    • Double syntax
    • Heredoc syntax
    • Newdoc syntax





    Single Quoted String 

    we can create a PHP string by single quote. Here is the example below and it's a easiest way.



    Example 


    echo $str;



    </body>
    </html>





    Kumar Atul jaiswal within a single quote




    Example 

    <!DOCTYPE html>
    <html>
    <head>

    <title> PHP Single Quotes </title>

    </head>
    <body>

    <h1> </h1>


    <?php

    $str =  'Kumar Atul jaiswal multiple line text within a single quote';

    $str1 = 'using double "Quote' directly inside single quoted string';

    $str2 = 'Using escape sequences \n in single quoted string' ';

    $str3 = 'using single quote  \'my self kumar Atul jaiswal\'  \\backslash ';

    echo "$str <br/> $str1 </br> </br> $str2 <br/> $str3 ";



    </body>
    </html>





    Kumar Atul jaiswal multiple line text within a single quote
    using double "Quote' directly inside single quoted string

    Using escape sequences \n in single quoted string
    using single quote  \'my self kumar Atul jaiswal\'  \backslash






    Now we will print a Number by single quote



    Example 

    <!DOCTYPE html>
    <html>
    <head>

    <title> PHP Single Quotes </title>

    </head>
    <body>

    <h1> </h1>

    <?php

    $num2 =   10;

    echo 'trying print a variable of $num2 ';



    </body>
    </html>






    trying print a variable of $num2









    Double Quoted string

    In PHP, we can specify string through enclosing text within double quote also. But escape sequences and variables will be interpreted using double quote PHP strings.




    Example 

    <!DOCTYPE html>
    <html>
    <head>

    <title> PHP Double Quotes String  </title>

    </head>
    <body>

    <h1> </h1>


    <?php

    $str =  "Kumar Atul jaiswal within a double quote";

    echo $str;



    </body>
    </html>





    Kumar Atul jaiswal within a double quote



    NOTE :-Now , we can use double quote directly inside double Quoted string but What Happened Next ?  lets see the example below 



    Example 

    <!DOCTYPE html>
    <html>
    <head>

    <title> PHP Data types String  </title>

    </head>
    <body>

    <h1> </h1>


    <?php

    $str =  "Using double "quote" directly inside double quoted string";

    echo $str;



    </body>
    </html>







    Parse error: syntax error, unexpected 'quote' (T_STRING) in C:\xampp\htdocs\double.php on line 24






    We can store multiple line text, special characters and escape sequences in a double quoted PHP string.




    Example 

    <!DOCTYPE html>
    <html>
    <head>

    <title> PHP Double Quotes String  </title>

    </head>
    <body>

    <h1> </h1>


    <?php

    $str =  "Kumar Atul jaiswal multiple line text within a double quote";

    $str1 = "Using escape sequences \n in double quoted string";

    $str2  = "Using double \"quote\" with backslash inside double quoted string";

    echo "$str <br/> $str1 </br>  $str2  ";



    </body>
    </html>





    Kumar Atul jaiswal multiple line text within a double quote
    Using escape sequences \n in double quoted string'
    Using double \"quote\" with backslash inside double quoted string









    Now we will print a Number by double quote



    Example 

    <!DOCTYPE html>
    <html>
    <head>

    <title> PHP Double Quotes String  </title>

    </head>
    <body>

    <h1> </h1>


    <?php

    $num2 =   50

    echo "Number is :  $num2 ";



    </body>
    </html>






    Number is : 50 








    Video On This Topic :  Soon 








    Have a Nice Stay Here : - )






  • 0 comments:

    Post a Comment

    For Any Tech Updates, Hacking News, Internet, Computer, Technology and related to IT Field Articles Follow Our Blog.