我有一个将数据发送到文本文件的表单,但我试图将所有发送的数据保留在该文本文件的第一行中,并用文本文件本身内的 br 标记替换可能的中断。抱歉,如果有一个非常简单的解决方案,但我已经搜索和测试了一个多小时了>_< (php 新手)
编辑:是的,这是我目前所拥有的一般要点。我正在使用变量。
我有一个表单,其中一个名为 content 的输入将数据发送到 Submit.php。
在submit.php...
$content = $_POST['content'];
并将以下内容发送到文本文件
$data = "$content";
$fh = fopen("file.txt", "a");
fwrite($fh, $data);
I have a form which sends data to a text file, but I'm trying to keep all data sent in the first line of that text file, and replacing would-be breaks with the br tags inside the text file itself. Sorry if there's a really easy solution, but I've been searching and testing for over an hour now >_< (php newbie)
Edit: Yeah here's the general gist of what I currently have. I'm using variables for it.
I have a form with one of the inputs named content that sends data to a submit.php.
In submit.php...
$content = $_POST['content'];
and that sends the following to a text file
$data = "$content";
$fh = fopen("file.txt", "a");
fwrite($fh, $data);
发布评论
评论(1)
看一下 php 函数
nl2br()
(php.net)。它完全满足您的需要,通过遍历您提供的字符串并用
s 和\n
\r
s) > 标签。显然
nl2br
并没有删除实际的中断,而只添加了 br 标签,所以尝试这个功能:Look at the php function
nl2br()
(php.net). It does exactly what you need, by going through the string you give it and replacing new lines (\n
s and\r
s) with<br/>
tags.Apparently
nl2br
doesn't remove the actual breaks, and only adds the br tags, so try this function: