![]() |
|
#1
|
|||
|
|||
Why "\n" is ignored when store into databaseI create form in PHP, and when I type something in text area will be stored into database. But when it display on screen, "\n" will be ignored. I check the table in database, the several lines becomes one line. I set charset is utf-8, suppose that it will get original format with content from text area. anyone knows how to solve this problem?
example: I typed in text area: "hi anyone, I have question about PHP, Could anyone help to solve the problem? thanks!" the output is: "hi anyone,I have question about PHP,Could anyone help to solve theproblem?thanks!" I want to get original format. How to do? |
|||
|
#2
|
||||
|
||||
Re: Why "/n" is ignored when store into databaseAre you viewing the output in an HTML page? If so, you need to insert <br> tags. You can do that with preg_replace. Example:
PHP Code:
__________________
www.blake-foster.com |
|
#3
|
|||
|
|||
Re: Why "/n" is ignored when store into databaseThanks! It works now.
|
|
#4
|
||||
|
||||
Re: Why "/n" is ignored when store into databaseYou're welcome.
__________________
www.blake-foster.com |
|
#5
|
||||
|
||||
Re: Why "/n" is ignored when store into databaseAlso, look at the PHP function nl2br(). Details: http://www.php.net/manual/en/function.nl2br.php.
As to your original question, the newlines are saved to your database and not "ignored" at all. If you look at your web page source (CTRL+U), you will see that the newlines are still there in your markup. However a web browser handles these newlines and carriage returns differently based on the HTML tags the string is in. If you want to preserve/display the text exactly the way you want, you need to place them inside <pre></pre> tags and if not, you should use the above-mentioned nl2br function. For example (within PRE tags): PHP Code:
HTML Code:
Example, with PHP's nl2br function: PHP Code:
HTML Code:
|
Recent GIDBlog
Vista ?Widgets? on Windows XP by LocalTech
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Restore Database | ajitham | .NET Forum | 2 | 16-Feb-2006 05:09 |
| store values | skyloon | MySQL / PHP Forum | 6 | 23-Jul-2005 03:29 |
| Limit combo box and date time picker choice according to database created in folder | shinyhui | C++ Forum | 0 | 22-Feb-2005 20:16 |
| Limit combo box and date time picker choice according to database created in folder | shinyhui | MS Visual C++ / MFC Forum | 0 | 22-Feb-2005 02:13 |
| Limit combo box choice according to database created in folder | shinyhui | MS Visual C++ / MFC Forum | 3 | 21-Feb-2005 21:58 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The