PHP换行符不起作用 [英] PHP New Line will not work

查看:237
本文介绍了PHP换行符不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一些代码,该代码首先读取文件中的现有内容,然后在新行上添加新代码行,但是我正在使用的代码只是将其添加到已经存在的新文本上现有行而不是新行...

Hi I am trying to create some code that first reads the existing contents of the file in and then adds the new line of code on a new line but the code i am using just adds it on the new text on to the already existing line instead of the new line...

这是我正在使用的代码:

Here is the code i am using:

<?php

$id = $_GET['id'];

$userfile = "user1.txt";
$fo = fopen($userfile, 'r') or die("can't open favourites file");
$currentdata = fread($fo, filesize($userfile));
fclose($fo);
$fw = fopen($userfile, 'w') or die("can't open favourites file");
$currentprocessed = "$currentdata\n";
fwrite($fw, $currentprocessed);
fwrite($fw, $id);
fclose($fw);
?>

我尝试了各种各样的想法,但没有任何效果,任何帮助将不胜感激.

I have tried a whole range of different ideas but nothing has worked, any help would be appreciated.

推荐答案

而不是附加\n,而是连接常量PHP_EOL,该常量始终是当前平台的正确换行符.

Instead of appending \n, concatenate the constant PHP_EOL which is always the correct newline character for the current platform.

您用来打开文本文件的程序也可能有问题.例如,Windows上的记事本无法理解Unix样式的换行符.

It might also be an issue with the program you're using to open the text file with. For instance, Notepad on Windows is incapable of understanding unix style newlines.

这篇关于PHP换行符不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆