[thelist] PHP echoing...

Eduardo Bacchi Kienetz eduardobk at via-rs.net
Mon Aug 19 10:55:00 CDT 2002


Single quotes are faster simply because whatever is inside it (even a
variable) is not processed, just outputed.
So:
<? $bla='test';
echo 'Testa' . '$bla\n';
echo "$bla"; ?>

Would output:
Testa$bla\ntest

<tip type="html editors and php" author="Eduardo Bacchi Kienetz">

To open php pages on html editors without having any kind of error
messages, one should use the following syntax (which is normally not
processed by html editors):

<script language="php">
echo 'bla';
</script>

instead of:

<?
echo 'bla';
?>

</tip>

Eduardo Bacchi Kienetz
http://www.noticiaslinux.com.br
http://www.agatetepe.com.br
Santa Maria - RS - Brazil

>Donald Noble wrote:
> > Hi evolters,
> >
> > I have been usingf PHP for a whileand was wondering what the
> > best/fastest way to output text is/ I assume is is dependant on the
> > particular situation, but any thoughts would be helpful.
> >
>
>1) I've never found the <? code ?> text <? code ?> method to be all that
>much faster. And I find it makes code quite ugly to read.  I use the <?=
>syntax in small templates quite often.
>example:
>file1 >> $foo = 'bar'; include('file2');
>file2 >> <?=$foo;?>
>
>2) single quotes are much faster than double quotes and I have huge scripts
>which show a noticable difference.
>example:
>file1 >>print 'foo '.$bar.' baz';
>is faster than
>file1 >>print "foo $bar baz";
>
>3) For long HTML dumps in php I often either use a template system but if
>it's just a one time thing I use the <<< syntax which isn't meant for speed
>but makes code easy to read.
>example:
>print <<<EOF
>blah
>EOF;
>
>4) This is offtopic but for people who don't know -- The ternary operator is
>a HUGE save in terms of time and code readability.  It offers no speed
>increase however. (it isn't slower though)
>example:
>if ($foo) {
>     foo_is_true($foo);
>} else {
>     foo_is_false($foo);
>}
>TURNS INTO:
>(($foo) ? foo_is_true($foo) : foo_is_false($foo));
>
>5) Last offtopic comment. -- If you are ever planning on making an
>application support multiple languages it is a good idea to begin writing
>strings as using the gettext() methods.  This will allow you to change the
>applications lanaguage at anytime without rewriting your code.  It does
>offer a speed hit though, so decide if you need it.
>example:
>file1 >> print _('my text'); // gettext() shorthand
>INSTEAD OF
>file1 >> print ('my text'); // inflexible but fast way
>
>
>Hope that helps and then some,
>davidu
>-davidu




More information about the thelist mailing list