Reliably Remove Newlines From String

前端 未结 6 1164
忘了有多久
忘了有多久 2020-12-21 06:52

The string input comes from textarea where users are supposed to enter every single item on a new line.

When processing the form, it is easy to explode the textarea

6条回答
  •  情深已故
    2020-12-21 07:15

    Following code must do the job

    $string) {
        $split[$k] = trim($string);
        if (empty($split[$k]))
        unset($split[$k]);
    }
    ksort($split);
    $join = implode('', $split);
    ?>
    

    to get string with newlinews completely stripped. It won't work correctly with JS though :(

提交回复
热议问题