Jump to content

Putting textfield information into a data base with formatting?


migroo
 Share

Recommended Posts

Okay I have a text field that updates a data base and every thing works great but I want to keep the formatting that is put into the text field (line breaks and extra spaces).I don't want some one to write me some code or anything but I have no idea where to start. Can anyone point me in the wright direction? I was looking at some php functions but I didn't see anything that would help me. I might of over looked something. Also does the data loose its formatting when you submit it or does it loose its formatting when I send it to the data base?Thank you.

Link to comment
Share on other sites

Look into the nl2br() function. When you retrieve your stored text use nl2br() and it will change newlines into breaks for you.

Okay I have a text field that updates a data base and every thing works great but I want to keep the formatting that is put into the text field (line breaks and extra spaces).
Link to comment
Share on other sites

Erm, note that the "formatting" is actually kept when you insert the data into the database - just not in a format that will be reproduced when outputting it as HTML. You will probably want to use nl2br() to convert newlines to break tags, and some form of manual replace for the multiple spaces.htmlspecialchars() only converts characters syntactically significant in HTML to their relevant entities. Also note that conversion should be performed when you retrieve the data, not when it is stored.

Link to comment
Share on other sites

Thank you all very much! This helps me a lot.

Link to comment
Share on other sites

Okay I finally got time to try out n12br() and it works great. I am still having trouble with the spaces though.I tried:

str_replace(' ', ' ', $row['about'])

And the html page still treats it like one space. I think this is because " " is the same as " " so it still treats them the same way.I can't use <pre> because it makes the text run out of the table cell that it is supposed to display in.I don't know what is left to try. If you have any ideas please let me know I am completely lost again.Thanks for all the advise I get from you all.

Link to comment
Share on other sites

And the html page still treats it like one space. I think this is because " " is the same as " " so it still treats them the same way.
HTML ignores multiple spaces. Anything over one space will display as one space. 5 spaces will display as only one, 300 spaces will display as only one, and so on. As synook said, you probably want to use the non-breaking space entity:str_replace(' ', ' ', $row['about'])
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...