# Print textarea in php



## peterjcs

I am having problem in printing/display the data that store in database. I use textarea to store the information into the database. But how to retrieve the information with the same formatting? I know it is possible to display the information into textarea, but because i want to print the information, so i do not want to use textarea box. 

Could someone please help? Thank you:wave:


----------



## gamerman0203

So your getting the data from a textarea and putting it into a database. You then want to get the data from the database and display it with the same formatting? What formatting are you talking about, exactly?


----------



## peterjcs

The example is as below:

-----------Example---------------------
1)this is the formatting that i want to appear at the screen.

2)When retrieve from database i want it appear exactly the same like this.

----------------------------------------

Above is the example:

When i use textarea to type and store the data to database, it store exactly the same as the formatting above. But the datatype at database must use "text". 

So, when i retrieve the data and display it on screen, i want it appear with same formating as above. I know it can be done by displaying the data into textarea box. But i do not want use textarea box. 

Just like this forum, what we type here will display exactly the same formatting.


Thank for your reply...ray:


----------



## peterjcs

Just make it clear, if i just print the data from the database, it will lose formatting, like all of the sentence will be join together.


If i just using echo to retrieve to display the data, it will end up like below.

-----------Example. this is wrong---------------------
1)this is the formatting that i want to appear at the screen.2)When retrieve from database i want it appear exactly the same like this.

----------------------------------------


-----------Example. This is what i want---------------------
1)this is the formatting that i want to appear at the screen.

2)When retrieve from database i want it appear exactly the same like this.

----------------------------------------


----------



## gamerman0203

oh ok, I gotcha.

I actually just over came this for a site I'm working on, but it is a slightly different situation...

this is what I did (assuming you're using php and a database):

$text = $_REQUEST['textarea'];
$text = str_replace("\n","<br>",$text);

What that is doing is taking the data from the textarea and assigning it to the $text variable. Then I'm looking for "\n", which is a text area line break, and replacing it with "<br>", which is an HTML line break, in the data assigned to $text. Once all that is done, it is reassigning the new result to $text again.

This works for me because I'm outputting to HTML and not to another textarea. I'm not quite sure how to do this, but I hope I got you on the right track.

P.S. I'll keep working on it since I am now intrigued!

UPDATE: use this before putting the data into the database: str_replace("\n","\n",$text) That should work.


----------



## peterjcs

ok, thank gamerman. I will try using your idea.


----------



## peterjcs

hello gamerman, i try your idea already and i work. Thank a lot. But, if you find any other solution, u r welcome to let me know. Thank gamerman.


----------



## gamerman0203

No problem! I'm glad I could help!


----------

