View Full Version : Print?echo?

23 Jan 2002, 20:08
Whats the difference be tween these two?

My book says that there the same, And I see Vb uses Echo everywhere. so ummmmmmmm whats the difference


Mark Hensler
23 Jan 2002, 20:17
one ASCII character ;)

Actually, theres more to it...
echo() can take multiple arguements (when enclosinge the parameters within parentheses).
print() will return TRUE on success and FALSE on failure.

They basically are the same. Just small, almost irrelevant differences.

24 Jan 2002, 01:55
ok so echo can do this

echo "somthing" "something" "something";

and print can only do this

print "something";


hey also there is one more thing that I am confused about what ezactly dose the command

/n do?

Thanks a lot ;)

24 Jan 2002, 03:27
Well form C++ i can tell you that \n is like when you hit enter or in html known as <br>

24 Jan 2002, 06:35
Okay, lets me see if I can help with this.

plain HTML lets HTML print out the text.
echo statement has php simply print out HTML code.
print statement is a function, so it uses more recourses.

This is for the most part how I have come to understand it. Many people have tested all three to see what is faster to use, and yes it's way to close to matter to most of us.

When I was first working with php I was using echo since that was all I really ever seen. Then I bought a PHP book and they used a "pro" looking print tag print(" "); that I started using. That is until I read that it's a function that has to process the HTML, well do I have to tell you what I'm back to using now? Right the echo tag. Straight HTML might be faster, but it looks less attractive and probably uses more characters when mixed with allot of php.

Mark Hensler
24 Jan 2002, 06:58
when sending echo() multiple arguements, use this syntax:
echo "somthing", "something", "something";

... you forgot the commas

/n does nothing, \n is a new line character ;)

24 Jan 2002, 19:59
whoops.. yeah that's what i meant.. lol

25 Jan 2002, 03:05
err, I am a little confused!

All print can do, is display text right??

So echo can display text, but dosn'nt need to be retyped?


print "hello, world:)"
print "this is a second test"


Echo "hello world","this is a second test"


O and by the way, thank you guys so much for taking your time;)

25 Jan 2002, 04:24
So they are the same, it's all about what your preference is. Use what ever you think looks better. Both function the same, and any speed differences are not a concern for the average user.

If you want just make a empty php page and play around testing out what works with what. If you get a parse error then it wasn't right. I've seen both tags used many different ways, it's just all about what you prefer.

Mark Hensler
25 Jan 2002, 07:32
The fact that echo() can take several arguements is really a mute point.... take this for example:

$var = "this";

// example 1
print $var . " is a string";

//example 2
echo $var, " is a string";

//example 3
echo $var . " is a string";
All three produce the exact same thing. print() may not be able to take several arguments, but who cares... both functions work with the dot (.) concat thingy. ;) Example 2 and 3 are exactly the same, even though 2 uses a comma and 3 uses a dot.

25 Jan 2002, 17:25
To all intents and purposes they are exactly the same :) They both do exactly the same thing and to my knowledge there are no speed differences.

Neither is a true 'function' so neither of them processes any of what you type. They are both language constructs not functions - see the php.net site for more information on this.

Which one you use is simply a matter of personal choice. I use echo() because that's what I used when I was learning PHP.

Mark Hensler
25 Jan 2002, 17:36
Check this out:
Quoted from PHP Doc: print() (http://www.php.net/manual/en/function.print.php)
print() is not actually a function (it is a language construct) so you are not required to use parentheses with it.

Quoted from PHP Doc: echo() (http://www.php.net/manual/en/function.echo.php)
// because echo is not a function, following code is invalid.
($some_var) ? echo('true'): echo('false');

// However, the following examples will work:
($some_var) ? print('true'): print('false'); // print is a function
echo $some_var ? 'true': 'false'; // changing the statement around
So... is print a function or not? ;)