You are here: Re: ECHO or concatenation with single quote, for performance? « PHP Programming Language « IT news, forums, messages
Re: ECHO or concatenation with single quote, for performance?

Posted by Michael Fesser on 05/30/07 19:18

..oO(L. Berger)

>I am working on an HTML template which has a lot of html tags, with
>PHP data shown in the middle of these tags -- you know, the usual.
>Currently, I have HTML as is, and many many "echo $variable"
>statements mixed in as PHP code.
>
>My question: should I leave it like this, with ECHO statements
>embedded within the tags,
>
>Or
>
>Should I concatenate the HTML within single quotes (single quotes are
>supposed to be faster in PHP than double quotes) and the display data
>as variables, and then ECHO that one concatenated string?

The fastest would be something like

echo 'some text ', $aVar, ' some more text ', $anotherVar;

No double-quoted string, no concatenation, just pure output. But I don't
consider that much of an issue. You should use what seems to be the most
appropriate to you, mainly in order to keep the code readable and
maintainable. For example instead of the code above I would usually use

print "some text $aVar some more text $anotherVar";

or even

printf('some text %s some more text %s',
$aVar,
$anotherVar
);

Definitely slower than the echo statement, but much more flexible and
more readable (at least for me), especially when there are a lot of
variables or statements required in the string.

Micha

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация