note 17025 added to function.print
| From: | greg at drymedia dot com | Date: | Thu, 22 Nov 2001 15:41:14 +0000 |
| Subject: | note 17025 added to function.print | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-21166@lists.php.net to get a copy of this message | ||
<p>One think I just spotted. Do not use print to output from functions if you want to embed
the result of the function within a string.<br>
For example:</p>function displayHW() {
print "Hello World";
}
$strMessage = "My first programming tutorial was ".displayHW().", was yours?";
print $strMessage;
<p>The output from this code is as follows:<br>
"Hello WorldMy first programming tutorial was, was yours?"<br>
You need to return "Hello World" and not print it for the desired
result.</p>function displayHW() {
return "Hello World";
}
$strMessage = "My first programming tutorial was ".displayHW().", was yours?";
print $strMessage;
<p>This will output:<br>
"My first programming tutorial was Hello World, was yours?"<br><br>Which is
correct. It's simple to see what the problem is but it's just as simple to make this
mistake as I had.<br>
I was using functions to dynamically produce Select boxes on forms, except they were being output in
the wrong place.</p>
--
http://www.php.net/manual/en/function.print.php
http://master.php.net/manage/user-notes.php?action=edit+17025
http://master.php.net/manage/user-notes.php?action=delete+17025
http://master.php.net/manage/user-notes.php?action=reject+17025