简体   繁体   中英

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

您可以使用HTML <pre>标记。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM