soma56 Posted July 9, 2010 Share Posted July 9, 2010 I'm trying to remove blank spaces after a textarea submit. For example: Blank space Blank space text1(enter key pressed) text2(enter key pressed) text3(enter key pressed) Blank space Blank space Everything I've researched says something like this should work (Confused as to why it's not): foreach ($mytextarea as $e) { if ($e == "") { $e = preg_replace( '/\r\n/', '', $e); } } I also thought a string replace would do the trick after checking the length: function validElement($element) { return strlen($element) > 1; } $mytextarea = array_values(array_filter($mytextarea, "validElement")); $mytextarea = str_replace("\r",'',$mytextarea; Neither seem to be working as when I: count($mytextarea); echo $mytextarea; I always see the extra 'return' as values in the array. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted July 9, 2010 Share Posted July 9, 2010 Assuming that $mytextarea is an array, doing this <?php $mytextarea = array_map('trim',$mytextarea); ?> should work. Ken Quote Link to comment Share on other sites More sharing options...
soma56 Posted July 9, 2010 Author Share Posted July 9, 2010 Thanks Ken, I appreciate it but it didn't work. I discovered that this did for anyone looking: <?PHP //Bring in Array Data $mytextarea = explode("\n", $_POST['mytextarea']); //Remove Return $mytextarea = str_replace("\r",'',$mytextarea) ; ?> The only difference from my original post, and likely what hindered the function correctly, is that I placed the 'str_replace' right after the $_POST. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.