简体   繁体   中英

Sending new line from textarea

I have a form collecting information to be stored in an sql database and displayed on a news feed.

One of the inputs is a text area and I want new lines input by the user to be displayed in the news feed. I'm guessing I want to do the formatting on the output with something like nltobr() and store the info as it's received but the problem is that the input is POSTed with the new lines as nothing but spaces:

<form action="postscript.php" method="post">
...
<tr>
      <td><label for"content">Content</label></td>
      <td><textarea id="content" name="content"></textarea></td>
</tr>
...
</form>


var_dump($_POST);
>>>>>>> array(1) {["content"]=> string(7) "a b c"}

so I guess the thing I want is a way to force the html form to send /r or something similar

Hope you can help, Thanks

The newlines are there. How could var_dump() yield "abc" with a string length of 7? It's because those white spaces are not spaces but actually newlines, where each white space is 2 characters as \\r\\n.

Try a string replace of where you echo str_replace("\\r\\n", "|", $_POST); You will get an output of a|b|c

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM