PHP MySQL New Lines / Whitespaces from textarea

I've a problem about whitespaces and new lines at the beginning of a textarea. I send a json string with ajax to the php script. Then I decode the string into an php array (with json_decode). So I have a string in this array with two line breaks at the beginning. If a print the text from the array, the line breaks are there, but if I store the text into the mysql database, the line breaks are gone... Only at the beginning of the string, the line breaks gone... At the rest of the string, the line breaks are ok.

Thanks for your answers! rob


In most browsers textareas' value parsed in a way, that the first character is ignored if it's a new-line.

<textarea>Value</textarea> <!-- value will be "Value" -->

</textarea> <!-- value will be "Value\n" -->



</textarea> <!-- value will be "\nValue\n\n" -->

Checked using javascript in Chrome / FF / Opera.

Probably(hopefully) you are doing some escaping / sanitizing before you store in the database. That probably trims your result, while in pure php the result is not trimmed.

Use PHP serialize() to make sure that you information stays the way it needs to be saved. Then add to database. When retrieving, call unserialize() to get all of you lovely information back.

Need Your Help

Uploading an image to a server in android

java php android image upload

I my app I am trying to send an image over a PHP server. The problem is the PHP programmers say that it should be sent as an data. Following is the code which I am currently using, please help me to

What libraries do I need to link my mixed-mode application to?

linker c++-cli mixed-mode

I'm integrating .NET support into our C++ application.