Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert text nto mysql and display back on page

Status
Not open for further replies.

chriszd

Technical User
Apr 21, 2008
42
MT
Hi Guys,

I have a small problem, well hope it is small. I created a normal input text box for the admin of a website to be able to insert his comments, news ecc from a web broswer into the database, so they can be then displayed on his website without him having to create or edit any html page.

this works great and the data is being displayed back also.

the only problem i have is that when you insert your text in paragraphs (below):

[
hello
I am testing
]

the text is displayed back in a one whole line (below):
[hello i am testing]

is there a way how i can insert the text into MYSQL from PHP in a way that it is stored exactly how i entered it?

I need a textbox exactly like the one I'm writing in right now.

THANKS ALOT :)
 
The text is stored exactly the same. The problem is elsewhere. HTML is white-space agnostic, meaning that any number of spaces, tabs or line breaks are displayed as a single space. If you look at your source code, you will see that all the spaces and line breaks are still there.

You can avoid this in a few different ways.

1. You can wrap the final text in the <pre> tags or change the css white-space property to pre on the element that holds the text. Pre tag (or its css equivalent) display the exact spacing as the actual text. However, the text will not wrap, so using <pre> usually brings more problems than it solves.

2. You could manipulate your text with the nl2br() function. This function will add a <br /> element to all the line breaks in the text. Since <br /> is HTML element for a line breaks, this method will allow you to see the same line breaks in the page as in the text area. This method will however not preserve multiple spaces or tabs. Additional issues with this method could be that <br /> might not be the most appropriate element (instead of two <br /> to make a paragraph break it is smarter to wrap text in <p> elements to begin with).

3. You could use one of the rich text editor options like [google]TinyMCE[/google] or [google]FCKEditor[/google] (google for those if you're interested). These solutions will be more javascript intensive but will allow people with less knowledge of html to apply some styling to the text.

___________________________________________________________
[small]Do something about world cancer today: Comprehensive cancer control information at PACT[/small]
 
Thanks for your reply,

im trying to implement one of the text editors, but its turning my mind up and down ...

will keep you updated.

thanks again.
 
i managed to work i used the nl2br function. thanks alot
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top