Closed Thread Icon

Topic awaiting preservation: Autoformatting textarea Pages that link to <a href="https://ozoneasylum.com/backlink?for=23991" title="Pages that link to Topic awaiting preservation: Autoformatting textarea" rel="nofollow" >Topic awaiting preservation: Autoformatting textarea\

 
Author Thread
Alexer
Bipolar (III) Inmate

From: Juneau, Alaska
Insane since: Jun 2004

posted posted 11-10-2004 22:19

I'm currently working on an application that allows the user to paste a press release into a textarea field and send it to a database. The unfortunate issue is that line breaks and paragraphs are not automatically inserted. Short of forcing my superiors to learn HTML, how can I convince the server to automatically interpret new paragraphs as <p>?

Any other autoformatting tips are also requested and appreciated. Thanks.

#emerge signature

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 11-10-2004 22:50

php?
Then you should check out php->nl2br. Or php->preg_replace if you are going to do something fancy.

so long,

->Tyberius Prime

mobrul
Bipolar (III) Inmate

From:
Insane since: Aug 2000

posted posted 11-10-2004 22:55

Your best bet would be some simple regex with PHP.
All sorts of really powerful stuff here, and fairly easy too.
[edit: damn you "fast-fingered TP". Beaten again... =)]

(Edited by mobrul on 11-10-2004 22:56)

Alexer
Bipolar (III) Inmate

From: Juneau, Alaska
Insane since: Jun 2004

posted posted 11-11-2004 00:04

Thanks for the suggestions.

I see how I can get php to replace a php line break (/n) with <br />, but thus far the breaks in the text box that are made by the user do not register as line breaks to the php script. What can I do to remedy that?

#emerge signature

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 11-11-2004 12:50

aeh... you're using a regular textarea? These things should end up as \r\n (on windows machines) in your php scripts.

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 11-11-2004 19:05

A line break is \n not /n that could cause a problem if you are using a regex.

Dan @ Code Town

Alexer
Bipolar (III) Inmate

From: Juneau, Alaska
Insane since: Jun 2004

posted posted 11-12-2004 19:02
quote:
A line break is \n not /n that could cause a problem if you are using a regex.



My bad. That was simply a typo on my part.

quote:
aeh... you're using a regular textarea? These things should end up as \r\n (on windows machines) in your php scripts.



Ah, I hadn't realized that. Armed with that newfound knowledge, I simply did a str_replace.. I ended up replacing every \n with a <p>.

Thank you all for your help (especially TP)

#emerge signature

« BackwardsOnwards »

Show Forum Drop Down Menu