开发者

Output form data into a single line

开发者 https://www.devze.com 2023-04-13 02:35 出处:网络
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.Sor

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);


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 (\ns and \rs) with <br/> tags.

Apparently nl2br doesn't remove the actual breaks, and only adds the br tags, so try this function:

function oneLiner ($str)
{
    $str = nl2br($str);
    $str = str_replace(array("\n","\r"), '', $str);
    return $str;
}  
0

精彩评论

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