在 PHP 中写入文本文件时换行符不起作用

发布于 2024-10-03 03:30:38 字数 434 浏览 0 评论 0原文

我有以下测试脚本:

<?php

$myFile = "testFile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "Floppy Jalopy\n";
fwrite($fh, $stringData);
$stringData = "Pointy Pinto\n";
fwrite($fh, $stringData);
fclose($fh);

?>

但是,当运行并使用记事本打开时,数据以单行形式返回,没有中断,如下所示:

Floppy Jalopy(疯狂盒子)Pointy Pinto(疯狂盒子)

,我找不到“疯狂盒子”的合适字符,但它确实是一个疯狂的盒子。有什么!

I have the following test script:

<?php

$myFile = "testFile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "Floppy Jalopy\n";
fwrite($fh, $stringData);
$stringData = "Pointy Pinto\n";
fwrite($fh, $stringData);
fclose($fh);

?>

when run however and opened usign Notepad, the data is returned in a single line without breaks as:

Floppy Jalopy(crazy box)Pointy
Pinto(crazy box)

where i cant find the appropriate character for 'crazy box' but its a REALLY crazy box. WHAT GIVES!

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

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

发布评论

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

评论(4

怪异←思 2024-10-10 03:30:38

最好使用 PHP_EOL。这是跨平台的,因此它会自动为 PHP 当前运行的平台选择正确的换行符。

$stringData = "Floppy Jalopy" . PHP_EOL;

PHP 常量

It is best to use PHP_EOL. This is cross-platform, so it automatically chooses the correct newline character(s) for the platform PHP is currently running on.

$stringData = "Floppy Jalopy" . PHP_EOL;

PHP Constants

半衬遮猫 2024-10-10 03:30:38

如果要在 Windows 记事本中打开文件,则必须使用 Windows 换行符:\r\n

If you want to open the file in Windows notepad, you must use Windows line breaks: \r\n

悲凉≈ 2024-10-10 03:30:38

你的代码运行良好。

使用 Notepad2Notepad++(如果您使用的是 Windows)。内置记事本无法处理 Unix 风格的行结尾。

Your code runs fine.

Use Notepad2 or Notepad++ if you're working on Windows. The built-in Notepad is unable to cope with Unix-style line endings.

不美如何 2024-10-10 03:30:38

。 PHP_EOL;将普遍适用

. PHP_EOL; will work universally

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