Jump to content

html formatting


thefortrees

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/60955-html-formatting/
Share on other sites

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();
?>

Link to comment
https://forums.phpfreaks.com/topic/60955-html-formatting/#findComment-303495
Share on other sites

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?>.

Link to comment
https://forums.phpfreaks.com/topic/60955-html-formatting/#findComment-306924
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.