将字符串传递到 codeigniter 的下载帮助程序时如何创建换行符

发布于 2025-01-04 21:51:48 字数 447 浏览 4 评论 0原文

将字符串传递到 codeigniter 的下载帮助程序时如何创建换行符。我尝试了下面的代码,它成功下载了文件和字符串,但它只是直接输出 \r\n 而不是将它们转换为新行。任何帮助将不胜感激:

$reportOutput = '';

foreach($data['displayPostingRecords'] as $result)
{
$reportOutput .=  rawurldecode($result['wpPostlink']).' \r\n ';
}

//download the file..
$fileName = 'report-articleBatchID-'.$articleBatchID.'.txt';
$this->load->helper('download');
force_download($fileName, $reportOutput); 

How do I create line breaks when passing a string into codeigniter's download helper. I have tried the code below which succesfully downloads the file and the string but it just outputs directly the \r\n rather than converting them into new lines. Any help would be greatly appreciated:

$reportOutput = '';

foreach($data['displayPostingRecords'] as $result)
{
$reportOutput .=  rawurldecode($result['wpPostlink']).' \r\n ';
}

//download the file..
$fileName = 'report-articleBatchID-'.$articleBatchID.'.txt';
$this->load->helper('download');
force_download($fileName, $reportOutput); 

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

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

发布评论

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

评论(1

梦在深巷 2025-01-11 21:51:48

抱歉,漫长的一天...将单引号更改为常规引号,这将解决您的问题。

$reportOutput = '';

foreach($data['displayPostingRecords'] as $result)
{
$reportOutput .=  rawurldecode($result['wpPostlink']) . "\r\n";
}

//download the file..
$fileName = 'report-articleBatchID-'.$articleBatchID.'.txt';
$this->load->helper('download');
force_download($fileName, $reportOutput);

Sorry long day... change the single tick quotes to regular quotes and that'll fix your problem.

$reportOutput = '';

foreach($data['displayPostingRecords'] as $result)
{
$reportOutput .=  rawurldecode($result['wpPostlink']) . "\r\n";
}

//download the file..
$fileName = 'report-articleBatchID-'.$articleBatchID.'.txt';
$this->load->helper('download');
force_download($fileName, $reportOutput);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文