开发者

line break problem

开发者 https://www.devze.com 2023-03-11 19:20 出处:网络
I am forcing a text file download but I don\'t get a line break in the text file. It shows \\r\\n header(\"Content-type: text/text\");

I am forcing a text file download but I don't get a line break in the text file. It shows \r\n

header("Content-type: text/text");
header("Content-Disposition: attachment; filename=testi.txt");
foreach($results as $result){
echo $result['xrt'].' '.$result['CMP'].'    '.$result['Add'].' '.$result['AFG'].'   '.'Times'.' '.$result['range'].'\r\n';
开发者_如何学运维}


You could use PHP_EOL

header("Content-type: text/text");
header("Content-Disposition: attachment; filename=testi.txt");

foreach($results as $result){
    echo $result['xrt'].'   '.$result['CMP'].'  '.$result['Add'].' '.$result['AFG'].'   '.'Times'.' '.$result['range'].PHP_EOL;
}

Or if you must type them, use: "\r\n"

header("Content-type: text/text");
header("Content-Disposition: attachment; filename=testi.txt");

foreach($results as $result){
    echo $result['xrt'].'   '.$result['CMP'].'  '.$result['Add'].' '.$result['AFG'].'   '.'Times'.' '.$result['range']."\r\n";
}


you need to use double quotes:

"\n\r"

check here for more info http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.double

0

精彩评论

暂无评论...
验证码 换一张
取 消