LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   [mod]_python: is there an equivilent to php's nl2br? (https://www.linuxquestions.org/questions/programming-9/%5Bmod%5D_python-is-there-an-equivilent-to-phps-nl2br-640937/)

BrianK 05-08-2008 08:58 PM

[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?

Hko 05-09-2008 04:57 AM

Quote:

Originally Posted by BrianK (Post 3147633)
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'))


BrianK 05-12-2008 12:35 PM

That's pretty clean. I like it.

Thanks!


All times are GMT -5. The time now is 08:30 AM.