Change url encode entities into html characters?
I used the jquery function serialize()
for a form, made an ajax call, and use php to do the form processing.
I have a textarea in that form w开发者_JAVA百科here users type uses spaces and line breaks. I can access the values with $_POST, but its doesnt interpret the line breaks into html <br/ >
tags. Is there a function that converts line breaks the urlencoded string into <br/>
tags and other html tags? Or is everything already decoded by the time i access it with $_POST that i cant do anything with it?
Use nl2br($text);
(new-line to break-rule)
Are you sure you are using nl2br() while echoing textarea's value ?
edit: too late:P
in PHP you have a function to add <br>
before any new line : nl2br()
You should use it only when you print the text in the textarea with echo, not for storing in your Database.
You also can find a use of addslashes() to avoid any problems with the caracteres '
and "
in your textarea
Alternatively, if you don't want to apply html tags into the value, you can later display the line spacing correctly by applying the CSS white-space
property into the element where the text appears, and setting it to pre
or something similar. For more information check out the documentation on it on w3schools.
精彩评论