简体   繁体   English

echo一个字符串,用br和水平标签替换nl和一些html字符

[英]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. 对于调试,我想用nl和水平制表符的html替换来回显或打印我的MySQL。

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

I can do echo nl2br($sql); 我可以做echo nl2br($sql); in order to replace \\n with <br /> . 为了用<br />取代\\n This gives me the screen output: 这给了我屏幕输出:

SELECT
*
FROM
`mytable`;

Now I want to swap the horizontal tabs for something like &nbsp; 现在我想交换水平标签,例如&nbsp; in order to indent them on the screen. 为了在屏幕上缩进它们。

What could I use instead of &nbsp; 我可以用什么代替&nbsp; , I've never liked it? ,我从来不喜欢它?

Thanks 谢谢

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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