Preserving indentation when inserting HTML from MySQL

Posted by Benjamin on Stack Overflow See other posts from Stack Overflow or by Benjamin
Published on 2010-04-14T20:36:26Z Indexed on 2010/04/14 21:03 UTC
Read the original article Hit count: 229

Filed under:
|
|

I am using MySQL and PHP to populate parts of a site, often with HTML stored in a TEXT field. I like to keep my HTML indented so that the source is neat and easy to read, for example:

<body>
   <div>
      <p>Blahblah</p>
   </div>
</body>

However, when the HTML is pulled from MySQL, I end up with:

<body>
   <div>
<p>Blahblahblah</p>
   </div>
</body>

This is quite ugly when there is a large amount of HTML being inserted into a DIV that is significantly indented. How can I stop this from happening? FYI, I use wordwrap() to keep each line from being too long.

© Stack Overflow or respective owner

Related posts about mysql

Related posts about html