LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-08-2008, 08:58 PM   #1
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
[mod]_python: is there an equivilent to php's nl2br?


I'm getting some text fields from a database that have newlines. Is there a simple way to convert the newlines to <br>\n in [mod_]python?
 
Old 05-09-2008, 04:57 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
Originally Posted by BrianK View Post
I'm getting some text fields from a database that have newlines. Is there a simple way to convert the newlines to <br>\n in [mod_]python?
I don't know if there is a builtin one, but it is easily made:
Code:
def nl2br(s):
    return '<br />\n'.join(s.split('\n'))
 
Old 05-12-2008, 12:35 PM   #3
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Original Poster
Rep: Reputation: 51
That's pretty clean. I like it.

Thanks!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache2 mod vhost_alias - problems with .htaccess mod rewrite d_t_baker Linux - Server 1 08-16-2007 07:32 PM
Problems using PHP's IMAP functions... LWillmann Red Hat 4 04-11-2004 01:55 PM
Python equiv of PHP's isset()? miknight Programming 2 07-09-2003 11:48 PM
PHP's imagecreatefromPNG function Tomasfuego Linux - Software 0 06-20-2003 12:58 AM
apache's OK, php's not matt Linux - Software 9 11-25-2001 09:24 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration