christopherisaak Posted January 14, 2012 Share Posted January 14, 2012 Hi, I'm new to this forum and new to PHP so forgive me if this is a silly question. I was just going through the first chapter and came upon the print language construct. I did some looking around when it was said that echo was another option to achieve the same result and wanted to find out why one would use print over echo or vise versa. I came upon a number of articles that said that echo could be insignificantly faster than print because it doesn't return anything whereas print returns a 1. Moving along a little bit I came to the point in chapter 1 where we have to escape some double quotations that are within the html code. I also found another source that has seemingly a much better way to do this. The book instructs us to type print "<a href=\"page.php\">link</a>"; why couldn't we just use echo '<a href="page.php">link</a>'; This is my source for the reason to use single quotes as opposed to double quotes on the outside: http://wolfprojects.altervista.org/articles/output-in-php/ Again, I am new to all of this and that is why I'm coming here to ask whether this is more appropriate than what is offered in the book. Thanks, Chris. Link to comment Share on other sites More sharing options...
Jonathon Posted January 14, 2012 Share Posted January 14, 2012 You can use either quote marks, I'm sure Larry goes on to use and explain either method (He does in the QuickPro Guide), in this case no way is more appropriate, it's down to preference and they both achieve the same thing. As for print vs echo there is little between them, echo is I believe ever so marginally faster. But print makes sense to newer programmers. 1 Link to comment Share on other sites More sharing options...
christopherisaak Posted January 18, 2012 Author Share Posted January 18, 2012 Thanks Jonathon for your quick response. So, would it be better for me, just starting out but planning to use php long term, to start forming a habit of using single quotes or using double quotes with escaping? Link to comment Share on other sites More sharing options...
Jonathon Posted January 18, 2012 Share Posted January 18, 2012 Just work your way through the book, you're aware of the difference and often you'll find yourself using both I suspect I know I do, but I tend to use single quotes more. Just preference :-) 1 Link to comment Share on other sites More sharing options...
Recommended Posts