Skip to content
Advertisement

fputcsv() problem. Textarea isn’t saved in one column

Today, I found my limit in data operations knowledge.

I can successfully save input fields as well as textareas by doing this:

JavaScript

Later on, I can retrieve the data and store it in array by using explode()… or so have I thought!

The problem is in me. I like BIG textareas. I am currently making a forum page and I would like to grant my visitors ability to break the line when creating a thread.

For instance:

JavaScript

This is the code I wrote so far:

let’s say, the input from the user looks like this

JavaScript

The user pressed ENTER 3 times making this thread..

JavaScript

in my threads.csv file, this is what’s been saved:

JavaScript

This is wished:

JavaScript

I want it to be saved in one row because the data cannot be retrieved at all. For example:

JavaScript

Now, I assure you. The page is blank. Nothing gets printed out, unless the data is saved in a single row like in example from above. I am open to any solution that features php code. I have no idea about .js whatsoever.

Respectfully Regarding,

I am crying

Advertisement

Answer

You can use str_replace() to replace any "rn" with a different text like <br />. Then you have the content in one line, which you can save via fputcsv(). The following example shows how to use str_replace():

JavaScript

This will generate the following output:

JavaScript

As you see the new lines ("rn") has been replaced by the <br /> HTML element and the content is in one line.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement