Search code examples
phpmysqlstyleshtml-entitieshtmlspecialchars

Styling outputted code from a database. PHP


I am trying to style my code that is being pulled out from the database. It is multi-lined code stored as a VAR-CHAR on a table "table1".

echo "<section class='styleElement'>" . htmlentities($code_display['Code']) . "</section>";

It displays the code fine, but it just places it all in a big block of text.

What I am asking is:

How do I indent each part correctly, and list all the elements so that it looks like a readable page.

The example: My page im working on

Any help would be appreciated. I have looked around, but most answers I find are more about the (htmlspecialchars / htmlentities).

I am not too bothered by colour coding the elements on the page, just the indentations, and numbering.

I am exploring the explode function at the moment, so I should now be ok.

Thanks. John


Solution

  • To format your output, use <pre> or nl2br().