0

I need to write a large block of html from a php file. To do this, I am closing an initial php block (using '?>'), then writing the html, followed by the new php block.

I need to access variables from the first php block in the second php block.

Could anyone explain the most efficient way to do this?

Right now, when I refer, in the second block, to a variable assigned with a non-zero value in the first block, I just get a returned value of 0.

Thanks for any help.

ploddingOn
  • 123
  • 1
  • 4
  • 12

1 Answers1

1

You should look in to something like a MVC development pattern.

The easiest way would be not to output everything in many blocks, but to append to a certain variable which is echoed at the end.

// code block
$html .= '<strong>Some html</strong>';

// other code block
$html .= '...';

// Other code

// At last, at the end
echo $html;
Mārtiņš Briedis
  • 17,396
  • 5
  • 54
  • 76