在 PHP 中生成可下载的 CSV 时是否可以打印退格字符?

发布于 2024-12-19 04:22:34 字数 379 浏览 5 评论 0原文

在 PHP 中生成输出时是否可以回显退格键?

情况:

if ($this->s) {
    header("Content-type: application/octet-stream");
    header("Content-Disposition: attachment; filename=exportevent.csv");
    header("Pragma: no-cache");
    header("Expires: 0");
    echo $this->s;
    exit;
}

我在我的一个视图(Zend MVC)中编写了上述代码,在打印 $s 时,附加了许多(30)个空白行。我想退格这些行。有什么方法吗?

Is it possible to echo backspace while generating output in PHP?

Situation:

if ($this->s) {
    header("Content-type: application/octet-stream");
    header("Content-Disposition: attachment; filename=exportevent.csv");
    header("Pragma: no-cache");
    header("Expires: 0");
    echo $this->s;
    exit;
}

I wrote the above code in one of my views (Zend MVC), while printing $s, a number of (30) blank rows are appended. I would like to backspace those rows. Is there any method for that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烂柯人 2024-12-26 04:22:34

如果必须删除回显点处的前导空白行,则要

echo ltrim($this->s);

删除回显之前的前导空格、换行符和回车符。

但您确实应该首先阻止生成这些行。

If you have to remove leading blank rows at the point of echo, then

echo ltrim($this->s);

to remove leading spaces, line feeds and carriage returns before the echo.

But you really should be preventing those lines from being generated in the first place.

怪我鬧 2024-12-26 04:22:34

你可以使用

  if(!empty($row)) {
  print $row;
  }

you may use

  if(!empty($row)) {
  print $row;
  }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文