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. Link to comment https://forums.phpfreaks.com/topic/207291-how-to-remove-carriage-return-in-array/ 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 Link to comment https://forums.phpfreaks.com/topic/207291-how-to-remove-carriage-return-in-array/#findComment-1083809 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. Link to comment https://forums.phpfreaks.com/topic/207291-how-to-remove-carriage-return-in-array/#findComment-1083820 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.