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 </textarea> <!-- value will be "Value\n" --> <textarea> Value </textarea> <!-- value will be "\nValue\n\n" -->
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.