Jump to content

Alternative to nl2br


Fmdpa

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...