I am using the TEXT datatype to store formatted text. The problem is, the formatting is lost once MySQL spits the data back out. Any idea on how I can preserve formatting? I've searched everywhere for the solution to no avail. EDIT: I'm using Ruby on Rails for this, so I don't think that PHP specific commands will be of much use. -------------- zac439 reports the following: here is the solution: "The solution to this problem in Ruby on Rails is fairly simple, as it turns out. Simple go to your model and put this at the very top: "before_create :fix_mytext" Now, create a definition: def self.TVAR = TVAR.downcase.gsub(/\n/,"<br />") end Simply replace "TVAR" with the name of your text area field. Now, before Ruby on Rails saves the data, it will format a "<br />" after every line. Meaning, the output is the same as the input! If anyone needs help implementing it let me know!" (also, could you PM me and let me know what course of action was taken? Thanks mods!)
I've never had any problems using TEXT before, everything is formatted the way I input it when I pull it from the database. To get the output to display correctly, I use this (it's CGI, not ROR, maybe it'll help, though): $TEXT_OUTPUT =~ s/\n/\<br>/g; Code (markup): Not sure if that'll fix your problem nor if you'll be able to use that code for your language. . .
I'm not familiar with CGI, so that doesn't help much. Especially since Rails does a lot of the database work automatically- so I don't even know if I could format things correctly without some work. I input page breaks on every line, and it came out of the datatable perfect. I guess I just need to figure out how to automatically put <br> tags after every line!
Sorry - that's the extent of my help. . . However, maybe you can input the formatted text as HTML & then just print the output as such? This is not always feasible nor possible, but maybe a consideration you might want to think about. Ah, I did a search... while I didn't find the answer, here's some "cheat sheets" for ROR to help you write the regex to switch the newline to a <br> http://www.ilovejackdaniels.com/cheat-sheets/ruby-on-rails-cheat-sheet/
Hmm, the tricky thing is that this is going to be user-input. So I'll have to either find a way to tack on the proper tags to specify a new line, or deal with the formatting after it comes out of the database. (Which is where it is obviously messing up) Thoughts?
Dude...I am having the same problem, it appears nop one knows how to fix this at all...I have posted all over the we all damn day and no on knows anything about this.
Right now I'm working on some code that will insert a <br> tag after every line break. Then we won't have to format it when it comes out of the database. I haven't worked on it in a long time, but I'm going to get some time in with it this weekend. I'll let you know how it goes.