Jump to content

Alternative to nl2br


Fmdpa
 Share

Recommended Posts

I'm trying to make do everything "properly" on my website. That, in my understanding, would exclude <br /> tags. Currently, my BBcode function uses the nl2br() function. How could I automatically convert paragraphs to block-level elements, instead?

Link to comment
Share on other sites

<p> tags? or BBC code paragraph? <p> tags are block level elements. can it be put into a p tag? or if not, in some HTML element that you can add a class to?

Link to comment
Share on other sites

That's one of the cases where user behaviour is vital to keep in mind... there is actually a paragraph separator character, but as you may have guessed, no one uses it (heck, I know about it, and I've never used it).Having <br /> is OK as long as the idea is to separate two lines. If the idea is to separate paragraphs, it's best that you look at the number of new lines. Two newlines means a new paragraph. And here it gets tricky... what about three and more new lines? Should you create a new paragraph? If you're as purist as trying to turn <br /> into <p>, then having an empty <p></p> is just as bad. Truncate all new lines into a new paragraph? What if the user intended to have a large space between his/her paragraphs? If you translate those new lines into margins of the paragraph, then OK, but that's not exactly trivial (though doable non the less).

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...