thefortrees Posted July 20, 2007 Share Posted July 20, 2007 Hi all - I am using Zend Studio to code all of my apps. To run the script and output HTML to the browser, I concatenate all the HTML and function output to a single variable then echo this variable at the end of the script. The problem is this - When I view source in the browser, all of the HTML is in one line. No formatting, no line breaks. So I started using "\n" at the end of every line to format the code. This is extremely cumbersome, and does not provide the proper HTML formatting. Is there anyway to format HTML code within PHP? Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted July 20, 2007 Share Posted July 20, 2007 There's nothing automatic that I know of to help you with this. Usually I just use the DOM explorer in the Web Developer toolbar for Firefox. Quote Link to comment Share on other sites More sharing options...
redbullmarky Posted July 20, 2007 Share Posted July 20, 2007 unless i've got this totally wrong, you could consider using HEREDOC or output buffering: <?php $out =<<<EOF <div id="test"> <h1>hello</h1> <p>world {$variable}</p> </div> EOF; ?> or <?php ob_start(); ?> <div id="test"> <h1>hello</h1> <p>world <?=$variable ?></p> </div> <?php $out = ob_get_clean(); ?> Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted July 20, 2007 Share Posted July 20, 2007 You could use tidy to format the HTML code so you can read it. Quote Link to comment Share on other sites More sharing options...
deadimp Posted July 25, 2007 Share Posted July 25, 2007 How are you adding your data to the variable? Are you using output buffer control? Or are you literally concatentating it to a variable? If the latter, I would highly suggest looking into output buffers. Plus, you can also handle escaping to HTML like this: <?php echo "Stuff "; ?> and even <?php echo "more stuff. "; $var="a little more"; ?> That, and maybe <?=$var?>. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.