explode textarea php (at new lines)

前端 未结 4 920
后悔当初
后悔当初 2020-12-08 01:04

can I do:

explode(\"\\n\", $_POST[\'thetextarea\']);

and have it work on all platforms? (The question I am asking is will it ever be \\r\\n

相关标签:
4条回答
  • 2020-12-08 01:07

    You should use:

    explode("\r\n", $_POST['thetextarea']);
    

    It will always be the same.

    Browsers and other user-agents will make sure they are :-)

    See http://www.w3.org/MarkUp/html-spec/html-spec_8.html#SEC8.2.1 for more info.

    0 讨论(0)
  • 2020-12-08 01:14

    You can do something like this:

    $text = trim($_POST['textareaname']);
    $text = nl2br($text);
    
    0 讨论(0)
  • 2020-12-08 01:22

    You could also use the PHP_EOL constant:

    explode(PHP_EOL, $_POST['thetextarea']);
    
    0 讨论(0)
  • 2020-12-08 01:34

    This will do the trick given \r\n, \r or \n:

    preg_split('/\r\n|[\r\n]/', $_POST['thetextarea'])
    
    0 讨论(0)
提交回复
热议问题