简体   繁体   English

如何在PHP文件中添加带有文本的新行?

[英]How do I add a new line w/ text in a PHP file?

OS: Ubuntu/Xfce, 14.04. 作业系统:Ubuntu / Xfce,14.04。

I have tried a bunch of solutions, but none of them worked for me. 我尝试了很多解决方案,但是没有一个对我有用。 I know that "/n", PHP_EOL, or "/n/r" should add a new line. 我知道“ / n”,PHP_EOL或“ / n / r”应该添加新行。 A form script from another file is suppose to add whatever was typed into a new line. 假设来自另一个文件的表单脚本会将键入的内容添加到新行中。 It won't go into a new line, just the first line. 它不会进入新行,仅进入第一行。

Here is my code: 这是我的代码:

$fp = fopen($_SERVER['DOCUMENT_ROOT']. "/HDdeltin/LoginSignup/Users/$con", "wb");
fwrite($fp,$text);
$writeemail = $email . "\n";
fwrite($fp,$writeemail);
fclose($fp);

What is wrong with the code? 代码有什么问题? Thanks 谢谢

You can try by using 您可以尝试使用

$writeemail = $email . PHP_EOL;

or 要么

$writeemail = $email . '</br>';

Try adding something like 尝试添加类似

 "<br/>".PHP_EOL.

br is the html line break tag. br是html换行标记。

PHP_EOL actually adds a newline in the source code which is not displayed by html rendering angines. 实际上,PHP_EOL在源代码中添加了换行符,而html渲染树不显示换行符。

If I've read your question right, you want to add a new line to the file and not overwrite it. 如果我已正确阅读您的问题,则要在文件中添加新行,而不要覆盖它。 My question would be, why are you still using PHP4 functions? 我的问题是,为什么还要使用PHP4函数? Use PHP5 functions, since they're better, easier to use and more comfortable. 使用PHP5函数,因为它们更好,更易于使用且更舒适。 Use this: 用这个:

file_put_contents($_SERVER['DOCUMENT_ROOT']. "/HDdeltin/LoginSignup/Users/$con", "\n".$email, FILE_APPEND);

If you're already on a new line (because you already append a new line to your string before you've written it to your file), move "\\n" to the other side of $email. 如果已经在新行中(因为已经在将新行写入到文件之前在字符串中添加了新行),请将“ \\ n”移至$ email的另一侧。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM