note 17025 deleted from function.print by jimw

From: Date: Fri, 14 Dec 2001 20:22:09 +0000
Subject: note 17025 deleted from function.print by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-22741@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>

« previous php.notes (#22741) next »