Deviant Logo

PHP question please? what is the purpose of echo()?

post details top
May 31st, 2010
post details top


what is the purpose of it and when do i know when to use it

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

6 Comments

  • Eugene

    echo — Output one or more strings

  • Joey

    Whatever text or var inside the command will be displayed inside of the webpage.

    echo(“test”); – that will print the word “test” on the webpage

    $text = “test”;
    echo($text); – that will also print “test” on the page.

  • kuyahh

    Echo/Print in php is used to output strings

  • Vladimir Ghetau

    Hi Hamlet,

    The PHP builtin function echo(), just like the print() one are used to output text. Basically, both functions work the same, try it:

    Step 1) Create a file, save it as PHP, e.g. “test.php”

    Step 2) Edit the file by adding the following code:

    < ?php

    // this is a comment, it will be ignored

    echo '1';
    echo ('2');
    echo '3';
    print '4';
    /*
    another comment (this time, a multiline one)
    what I'm doing here is to show you different
    ways to output text inside browsers using PHP
    */
    ?>

    Step 3) Save the “test.php” file after you’re done with the editing part.

    Step 4) Put “test.php” on your webserver, and access it using your browser at http://serverhostname/test.php – You will see on the page, the following text, based on the example provided at step 2:

    —————– browser top ———————
    1234
    —————– browser bottom —————-

    Enjoy :)

  • Gonzo

    echo() is the same as print() except it supports multiple expressions where as print cannot. Both output a string.

    example: echo “The first”, “the second”;

  • BIG FOOT

    echo is to output to the screen. if the name is confusing -

    use print(); – it is the same thing.

Leave a Reply

Search

  • Partner links