I've noticed that if I make a php script like this;

<?php
print "hello";
?>

...it gets the same result as when I do this;

<?php
echo "hello";
?>

So, could someone please tell me what the difference between "print" and "echo" is?

Thanks

    There is no difference. They are exactly the same. I use echo, however, purely because it's quicker to type.

      There is a difference between print and echo.

      While both are language constructs, print can act like a function (PHP Manual notes that it can be used in terms of variable functions), and returns boolean values, while echo cannot.

        ... you can use echo to call up a previously defined function, but you can't use print. Check the manual for further details.

        How you getting along?

        Norman

          Thanks for the updates guys. I appreciate that.


          Norman... it's going great.

          I've had my share of ups and downs but a few hours ago I had a very big moment when I managed to do my first ever PHP script that takes stuff from a website HTML form and chucks it into a database.

          But, I've got still got a long way to go.

          I don't know about you, but for me the hardest part with all this stuff has been setting it all up and running (i.e., setting up MySQL, Apache and all that jazz).

          How's your own site going Norman?

            Hi David

            If you're already taking stuff from a form and inserting it into a database, you're moving along very swiftly indeed. Is this a form asking for user input, because if it is, I hope you're including security measures to stop bad bstrds from inserting nasty scripts. Check out the manual if you don't know what I'm talking about, e.g. http://www.php.net/htmlspecialchars

            My own little site is coming along - the 'landscapes' page and the 'links' page both now contain content. The links page needs some work - I need to split it into sections for different topics, e.g. music, with a link to Top Gig.

            Btw, are you aware of http://www.firstfoot.com? Very funny - check out the Good Pop and Bad Pop pages.

            Norm 😃

              Write a Reply...