SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Evangelist barbara1712's Avatar
    Join Date
    Apr 2007
    Location
    India
    Posts
    509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    diff bet. echo,print and printf

    Hello All,

    I want to know the exact difference between echo,print and printf
    I want to know weather print if a function or not.

    Thanks,
    Barbara

  2. #2
    Always learning kigoobe's Avatar
    Join Date
    May 2004
    Location
    Paris
    Posts
    1,565
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Print is not a function, but a language construct.

    Echo tends to be insignificantly faster than print.

    Never used printf.

  3. #3
    SitePoint Guru Ize's Avatar
    Join Date
    Nov 2005
    Location
    The Netherlands
    Posts
    808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just took some tests:

    PHP Code:
    $execution_start microtime(true);
    echo 
    '<ul>';
    for (
    $i=0$i<10000$i++)
    {
        echo 
    '<li>new string ' .$i'</li>';
    }
    echo 
    '</ul>';
    $execution_end microtime(true);
    $execution_time $execution_end $execution_start;
    print 
    '<p>took: ' round($execution_time,4) . ' seconds</p>'
    with both print and echo.
    I executed 10 times for each function and these are the average results:
    Code:
    echo: 0.09278 seconds
    print: 0.09146 seconds
    Rather insignificant indeed

  4. #4
    SitePoint Evangelist barbara1712's Avatar
    Join Date
    Apr 2007
    Location
    India
    Posts
    509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I come to know that printf is a function which returns the value of 1 or 0
    depending upon success.
    But still I am having doubt in echo and print.
    Barbara

  5. #5
    Always learning kigoobe's Avatar
    Join Date
    May 2004
    Location
    Paris
    Posts
    1,565
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For all practical purposes, I think you can use any of them, echo or print, without any concern.

  6. #6
    SitePoint Wizard bronze trophy devbanana's Avatar
    Join Date
    Apr 2006
    Location
    Pennsylvania
    Posts
    1,736
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    echo returns no value
    print returns a success value
    printf prints a formatted string

    For example:

    PHP Code:
    printf("Hello %s\n"$name); 
    Laudetur Iesus Christus!
    Christ's Little Flock
    Jesus is the Good Shepherd


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •