Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: Converting plain text to HTML and back again

by Dog and Pony (Priest)
on Jul 08, 2003 at 06:08 UTC ( #272205=note: print w/replies, xml ) Need Help??

in reply to Converting plain text to HTML and back again

Having a checkbox, or possibly autodetect sounds like a good idea. When the user is using HTML, don't apply any other formatting, but let the user take full responsibility. Save the choice as a boolean in the database as well,so you know what processing, if any, to make when it is time to produce output.

Another option is to disallow <p> and <br>, so you can make replacements in all of them, but that is probably not so popular. Or to make it harder on yourself, try to guess what to do, ie /<br>\n/ does not get replaced, while a single \n will. Probably not a good route.

In some kinda-similar solutions I've also had both types of data saved side-by-side in the database, especially when there would be a lot of processing overhead otherwise. DB size is rarely *that* important, after all. This could be useful in that when somebody saves a pure-text post, you also save a HTML version, but you still have the pure text for the email etc.

Trying to format texts back and forth might be a bad idea, lots of special cases and whatnot. A one-off conversion from one to the other should probably be much more reliable in the long run. At least any bugs should be easily spotted and fixed, as opposed to a text that has gone from HTML to text to HTML to... if your users can edit posts for instance, that could happen really fast. :)

You have moved into a dark place.
It is pitch black. You are likely to be eaten by a grue.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://272205]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2017-09-26 02:29 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (291 votes). Check out past polls.