Jump to content


Photo

Textarea and adding carriage returns


  • Please log in to reply
3 replies to this topic

#1 kensmith

kensmith
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 22 December 2004 - 08:00 PM

I paste and copy articles in to a textarea. When I save it to a MYSQL table and then re-read the data, it is all strung together.

If I physically type <br> after each carriage return, I get the expect results.

How can I do this without having to type <br> manually?

Thanks, Ken

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 22 December 2004 - 08:10 PM

I paste and copy articles in to a textarea. When I save it to a MYSQL table and then re-read the data, it is all strung together.

If I physically type <br> after each carriage return, I get the expect results.

How can I do this without having to type <br> manually?

Thanks, Ken

View Post

check out the nl2br() function. if you input the textarea value as nl2br($textareaValue), it will change all the newlines to <br /> for you!
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 kensmith

kensmith
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 22 December 2004 - 08:55 PM

check out the nl2br() function.  if you input the textarea value as nl2br($textareaValue), it will change all the newlines to <br /> for you!

View Post


Thanks, that worked great. Now I have to go through my 200+ articles and remove the <br> from all of them! LOL

Thanks.

#4 Pilot-Doofy

Pilot-Doofy
  • Members
  • PipPip
  • Member
  • 19 posts
  • LocationMustywindows.com!

Posted 22 December 2004 - 09:57 PM

Thanks, that worked great. Now I have to go through my 200+ articles and remove the <br> from all of them! LOL

Thanks.

View Post

You can just do this:

// replace <br> with <br /> even though i dont know why lol

## get all the stuff from the database

$text = $array_retrieved_from_database['field']; // change this to fit
$cur_id = $array_retrieved_from_database['field_id']; // change this to fit
$text = str_replace("<br>", "<br />" $text);

mysql_query("UPDATE table SET field = '$text' WHERE id = '$cur_id'");

Hope that helped.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users