"n" be transformed into "<br>" automatically

Asked

Viewed 57 times

3

I’m developing a PHP posting system with Mysql. I need the line breaks that user enter in textarea are converted into <br />.

The variable $texto (contains the content of the post) goes to the database in the column conteudo (text type).

When the user breaks the line on textarea, a space is automatically added. I needed to replace this space with a <br />.

1 answer

2


nl2br

(PHP 4, PHP 5, PHP 7) nl2br - Inserts HTML line breaks before all newlines in a string

Description

string nl2br ( string $string )

Returns string with <br /> inserted before all newlines.

  • Perfect! Exactly what I needed! Thank you! (when you give the minimum time, I accept the answer)

  • 2

    I recommend that you save the original version with nl, and use the function when displaying it as HTML, it is more practical if you need to put the content in a textarea for editing...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.