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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.