0

I'm trying to use a heredoc string in one section of my script, and inside this heredoc string is a function from inside a class that inputs some dynamic bit of stuff.

The function outputs the code correctly... but in the wrong place. Here's what I mean:

$output = <<<HTML
blah blah
blah
blah blah
<select>
{$admin->dropAcctNumbers()}
</select>
blah blah
blah
HTML;

When this is displayed in the web browser, it shows the code echo'd from inside the dropAcctNumbers() all the way up here:

    <option>Account Numbers</option>
blah blah
blah
blah blah
<select>
</select>
blah blah
blah

When it should be here:

blah blah
blah
blah blah
<select>
    <option>Account Numbers</option>
</select>
blah blah
blah

Any ideas?

jdstankosky
  • 657
  • 3
  • 15

2 Answers2

1

Your method $admin->dropAcctNumbers is printing information instead of returning it ..

Example

echo "<pre>";
$admin = function () {
    print "    Account Numbers";
};

$output = <<<HTML
blah blah
blah
blah blah
{$admin()}
blah blah
blah
HTML;

echo $output;

Output

    Account Numbersblah blah
blah
blah blah

blah blah
blah

And

echo "<pre>";
$admin = function () {  return "    Account Numbers" ; } ;

$output = <<<HTML
blah blah
blah
blah blah
{$admin()}
blah blah
blah
HTML;

echo $output ;

Output

blah blah
blah
blah blah
    Account Numbers
blah blah
blah
Baba
  • 94,024
  • 28
  • 166
  • 217
  • I'm not sure I want the `
    ` tag... I modified my example slightly to reflect what's actually going on.
    – jdstankosky Oct 10 '12 at 18:16
  • The two cases ... are 100% different ... but they would still give different result See Print : http://codepad.viper-7.com/XU01jm and See Return : http://codepad.viper-7.com/U4Ni0q – Baba Oct 10 '12 at 18:25
0

try this

echo "<pre>".$output."</pre>";
Sivagopal Manpragada
  • 1,554
  • 13
  • 33