MultiDev
MultiDev

Reputation: 10659

Saving textarea contents to mysql then displaying correctly on page

I am trying to save the contents of a textarea into a mysql database, then echo the contents on the page at a later time.

Here is what Im doing:

In the textarea, I literally type:

Hello

How's life?

To store it in mysql, I am using:

$textarea = mysql_real_escape_string($_POST['textarea']);

In mysql, it looks like:

Hello\r\n\r\nHow\\\'s life?

To echo onto the page, I am using:

echo nl2br($textarea);

But, it is still echoing out exactly as it is shown in mysql. How do I remove the extra \'s from the output and also display the contents on the proper line?

Thanks

Upvotes: 2

Views: 1119

Answers (1)

Trent Earl
Trent Earl

Reputation: 3617

Try using:

echo preg_replace('/[\s]+/', ' ', stripslashes($textarea));

stripslashses returns a string with backslashes stripped off.

Upvotes: 2

Related Questions