nikolay
nikolay

Reputation: 59

How do I keep textarea line breaks when fwrite with php?

I am making a text bin like pastebin or hastebin.

In my index.php I have: index.php

In my uploader.php I have: uploader.php

When I do that, the output does everything I want but in the .txt it will break a line but on the php post it wont. E.g.

In .txt file:

Hello
Hello

would show up as

Hello 
Hello

but in the php it would show up as

Hello Hello

Can someone please help me?

Note: I'm running on localhost but I'm gonna upload it to my site!

Upvotes: 1

Views: 96

Answers (2)

Khan Luke
Khan Luke

Reputation: 168

Been here before. I hope you are using mysqli_real_escape_string to save into database or PDO. Its safe and prevent errors.

When outputting your content use nl2br. For example:

<?php  echo nl2br($mystring);  ?>

This will preserve line breaks.

Upvotes: 1

Alonso Urbano
Alonso Urbano

Reputation: 2261

The easiest way, if you are displaying the text in HTML format, is to put all of the text inside a <pre> block:

<pre>Hello
Hello</pre>

Upvotes: 0

Related Questions