Re: note 8458 added to echo

From: Date: Wed, 13 Sep 2000 10:17:03 +0000
Subject: Re: note 8458 added to echo
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-4857@lists.php.net to get a copy of this message
jj@comberg.cz writes: > Weird behaviour of echo and print outpup. > > PHP3 prints variable text that should be interposed between two > static texts infront of the whole text. > > The following code: > > echo("<a > href=\"javascript:pravy('messages.php3?folder=$folder[$i]');levy('folders.php3')\">" > . trans($folder[$i]) . " ($msg_num)</a><br>\n"); > > produces: > > Received mail<a > > href="javascript:pravy('messages.php3?folder=INBOX');levy('folders.php3')"> > (9)</a><br> > > Where "Received mail" is the text that should have occurred inside > the hyperlink. trans(str) is my function that searches an > associative array of strings and returns string in the actual > language. > > I have absolutely no idea why echo produces something it was not > told to produce. When used from other places in my code, trans() > works as expected. > > Regards, > Jakub Jermar > > http://www.php.net/manual/function.echo.php I've just deleted this note: if you're having a problem with PHP, please post to the mailing list at php-general@lists.php.net. The manual errata is for submissions of text to be included into the manual, so chances are way, way better that someone will come across your note on the mailing list than in the manual errata. :) Please make sure to read the instructions at http://www.php.net/manual/add-note.php before adding another note. As to your problem--what you are describing would happen if trans() was *echoing* its text. The way you are trying to use it above would only work if trans() was *returning* its text. This is because when the PHP parser hits that line in the code, it has to figure out what all the text is before it can echo it. Thus, trans() gets called before the echo happens. So any text echoed from that function gets printed first, then the function returns, and the original echo occurs. Whew. Not the clearest explanation I've ever perpetrated. :) Blame the beer. Hope it helps, Torben -- +----------------------------------------------------------------+ |Torben Wilson <torben@php.net> Netmill iTech| |http://www.coastnet.com/~torben http://www.netmill.fi| |Ph: 1 250 383-9735 torben@netmill.fi| +----------------------------------------------------------------+

« previous php.notes (#4857) next »