LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-15-2008, 05:21 AM   #1
snowtigger
Member
 
Registered: Mar 2005
Location: england
Distribution: slackware, win2k
Posts: 364

Rep: Reputation: 35
php, printf vs echo


Well i'm on a journey to php land, and i'm after any comments, advice, pros or cons of using "printf" or "echo".

Which would you say is more suitable? Is one better at one job than the other?

 
Old 06-15-2008, 06:47 AM   #2
Clemente
Member
 
Registered: Aug 2003
Distribution: Debian, Ubuntu
Posts: 188

Rep: Reputation: 30
I would say, the answer derives from comparing following pages with regard to what you want to do:

printf
echo

First is more flexible and a real function. Latter one is a language construct, less flexible but more easy and quick to write.

I cannot give any evidence, but I would bet, that echo processes faster than print.

Clemente
 
Old 06-15-2008, 07:04 AM   #3
CSIG
LQ Newbie
 
Registered: Apr 2008
Posts: 11

Rep: Reputation: 1
function VS language construct

'echo' and 'print' are not a functions, but a language constructs, so you won't be able to use it in the same way as 'printf'.

'printf' takes input differently: you can provide a format string and then list all the required input (just like in C/C++). 'echo' and 'print' only take strings.

For common cases the difference is not obvious at first sight, and quite often not even relevant. In some special cases 'printf' can be better.
 
Old 04-17-2009, 02:47 AM   #4
doru
Member
 
Registered: Sep 2008
Distribution: Ubuntu 8.04 LTS Server
Posts: 115

Rep: Reputation: 19
good faq

http://www.faqts.com/knowledge_base/...l/aid/1/fid/40
 
  


Reply

Tags
echo, php, printf


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
php: echo command behaviour ChrisScott Programming 2 08-04-2007 07:28 PM
PHP and JavaScript: problem with echo()-ing unwanted line breaks Robhogg Programming 3 02-12-2007 07:52 AM
echo current user with PHP genderbender Programming 1 05-10-2006 06:03 PM
echo does not work in php code suchi_s Programming 3 10-21-2004 03:39 AM
using 'echo' in a system statment in php evilchild Programming 3 09-23-2004 02:27 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration