Capture newline from a textarea input

后端 未结 3 1187
遥遥无期
遥遥无期 2020-11-30 09:06

I have a textarea form in my html. If the user hits enter between 2 sentences that data should be carried over to my PHP.

Currently if the user enters:



        
3条回答
  •  渐次进展
    2020-11-30 09:28

    This is because when you echo it it's being displayed as HTML. A \n character is interpreted as a space. If you view the source you'll see your desired output.

    To convert \n to
    use:

    echo nl2br( $str );
    

提交回复
热议问题