doushi2902 2014-03-23 14:14
浏览 58

如何在PHP 5.4中打印空白字符串? [关闭]

I tried using the '' or ' ' empty strings in PHP but it seems to have been trimmed when using the echo statement for displaying it in the browser.

echo '   the quick brown fox jumps over the lazy     dog.';

The statement above is been stripped of the white/blank spaces.

How can I do this in PHP? How can I print blank lines without them being stripped out?

  • 写回答

1条回答 默认 最新

  • dongpao1926 2014-03-23 14:19
    关注

    PHP isn't stripping anything; your browser is ignoring the space. Right-click, View Source and you'll see what I mean. Either wrap the whole string in a <pre> tag, or use a non-breaking space, e.g., &nbsp;, for each piece of whitespace you want to leave. (Or use style='white-space: pre;' on the element.)

    echo '&nbsp;&nbsp; the quick brown fox jumps over the lazy &nbsp;&nbsp;&nbsp; dog.';
    

    Or:

    echo '<pre>   the quick brown fox jumps over the lazy     dog.</pre>';
    

    Or:

    echo '<p style="white-space: pre;">   the quick brown fox jumps over the lazy     dog.</p>';
    

    Or (@SecondRekudo):

    Or send a Content-type: text/plain header.

    Which would look like:

    header('Content-type: text/plain');
    

    Which needs to be called before any output to the browser (or you'll get a warning and the header won't be sent).

    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?