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.

5
  • 1
    stackoverflow.com/questions/5126261/… Commented Apr 21, 2012 at 21:54
  • 2
    The variable should still have a value in the next block. Show us some code. Commented Apr 21, 2012 at 21:55
  • @OrangeTux I think you should post this link as an answer. Commented Apr 21, 2012 at 22:00
  • Answer can be found here. stackoverflow.com/questions/5126261/… @pyrate :done Commented Apr 21, 2012 at 22:12
  • OK thanks all, your comments have let me understand the problem better. I will be using suggestion by Martins Briedis (below) to solve. Commented Apr 22, 2012 at 10:47

1 Answer 1

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;
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, will be using this approach.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.