NYCPHP Meetup

NYPHP.org

[nycphp-talk] Changing "\n" in textarea

Dan Cech dcech at phpwerx.net
Sat Feb 7 09:01:46 EST 2004


If you want to generate 'proper' closed tags you should use:

$newtext = '<p>' . str_replace ("\n",'</p><p>',trim ($oldtext)) . '</p>';

or for '<br />' tags:

$newtext = str_replace ("\n", '<br />', trim ($oldtext));

The trim is used to prevent extra tags being appended if there are any 
trailing or leading newlines.

Dan

keith at keithjr.net wrote:
> $newtext = str_replace("\n","<p>",$oldtext);
> 
> that would replace any newlines with new paragraph tags in html. You could
> also use <br> for the newline.
> 
> 
>>Okay, noob here.
>>
>>I am using a textarea for a form that will get put into a MySQL text
>>column. The problem is that I have it write to a flat file first, lines
>>terminated by newlines.
>>
>>How do I pull out newlines in the text area and make then "<p>" type
>>things before it get written to the flatfile?
>>
>>ciao!
>>
>>leam
>>
>>_______________________________________________
>>talk mailing list
>>talk at lists.nyphp.org
>>http://lists.nyphp.org/mailman/listinfo/talk
>>
> 
> 
> _______________________________________________
> talk mailing list
> talk at lists.nyphp.org
> http://lists.nyphp.org/mailman/listinfo/talk
> 





More information about the talk mailing list