-->

  • php echo and print statement




    PHP Echo and Print Statement 

    In PHP, there are two basic ways to get output : echo and print


    PHP echo and print statements 


    Echo and print are more less or less the same. They are both used to output data to the screen.
    The difference are small :




    The PHP Echo Statements


    The echo statements can be used with or without parentheses :  echo or echo ( ) .



    Example 


    <!DOCTYPE html>
    <html>
    <head>

    <title> PHP Echo Statements </title>

    </head>
    <body>

    <h1> </h1>


    <?php

    echo "Hi, my name is Kumar Atul Jaiswal";
    echo "<br>";          // This is break line
    echo "I love php

    ";
    echo "<br>";
    echo "I'm about to learn PHP!<br>";
    echo "This ", "string ", "was ", "made ", "with multiple parameters.";

    ?>



    </body>
    </html>




    Output 


    Hi, i am Kumar Atul Jaiswal 
    I love php
    I'm about to learn PHP!

    This string was made with multiple parameters.









    Example 

    <!DOCTYPE html>
    <html>
    <head>

    <title> PHP  Echo </title>

    </head>
    <body>

    <h1> </h1>


    <?php

    $x = 6;
    $y = 8;


    $txt = "www.kumaratuljaiswal.in";
    echo "I Love " .  $txt  . ;

    $x = 5;
    $y = 7;


    $txt1 = "Learn PHP";
    $txt2 = "www.kumaratuljaiswal.in";

    echo "<h2>" . $txt1 . "</h2>";
    echo "Study PHP at " . $txt2 . "<br>";
    echo $x + $y;

    ?>



    </body>
    </html>




    Output 

    I Love www.kumaratuljaiswal.in

    Learn PHP
    Study PHP at www.kumaratuljaiswal.in

    12





    The PHP Print Statement

    The print statement can be used with or without parentheses: print or print().

    Example 

    <!DOCTYPE html>
    <html>
    <head>

    <title> PHP  Print Statements </title>

    </head>
    <body>

    <h1> </h1>


    <?php

    print "<h2>I love PHP !</h2>";
    print "Hello world!<br>";

    print "I'm about to learn PHP!";


    ?>



    </body>
    </html>




    Output 

    I love PHP
    Hello world
    I'm about to learn PHP



    • Display Variable 


    The following example shows how to output text and variables with the print statement:



    Example 



    <!DOCTYPE html>
    <html>
    <head>

    <title> PHP  Print Statements </title>

    </head>
    <body>

    <h1> </h1>


    <?php

    $x = 5;
    $= 7;


    $txt1 = "Learn PHP";
    $txt2 = "www.kumaratuljaiswal.in";

    print "<h2>" . $txt1 . "</h2>";
    print "Study PHP at " . $txt2 . "<br>";
    print $x + $y;

    ?>



    </body>
    </html>




    Output 



    Learn PHP
    Study PHP at www.kumaratuljaiswal.in

    12






    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.