user783322
user783322

Reputation: 481

echo a string, replacing nl with br and horizontal tabs with some html char

For debugging I want to echo or print my MySQL with html replacements for the nl and horizontal tabs.

$sql="
SELECT
    *
FROM
    `mytable`;";

I can do echo nl2br($sql); in order to replace \n with <br />. This gives me the screen output:

SELECT
*
FROM
`mytable`;

Now I want to swap the horizontal tabs for something like &nbsp; in order to indent them on the screen.

What could I use instead of &nbsp;, I've never liked it?

Thanks

Upvotes: 1

Views: 254

Answers (1)

AndrewR
AndrewR

Reputation: 6748

You could use the HTML <pre> tag.

echo '<pre>' . $sql . '</pre>';

Upvotes: 3

Related Questions