curt22 Posted August 30, 2007 Share Posted August 30, 2007 How can I remove ALL whitespace (NOT just spaces) from a string, and Not just at the beginning and end. Link to comment https://forums.phpfreaks.com/topic/67365-solved-remove-whitespace/ Share on other sites More sharing options...
pocobueno1388 Posted August 30, 2007 Share Posted August 30, 2007 <?php $str = "There should be no spaces"; $str = str_replace(' ', '', $str); echo $str; ?> Link to comment https://forums.phpfreaks.com/topic/67365-solved-remove-whitespace/#findComment-337973 Share on other sites More sharing options...
curt22 Posted August 30, 2007 Author Share Posted August 30, 2007 Thanks pocobueno1388, but I want to remove all kinds of whitespace like \t \n and all other space characters. Link to comment https://forums.phpfreaks.com/topic/67365-solved-remove-whitespace/#findComment-337975 Share on other sites More sharing options...
effigy Posted August 30, 2007 Share Posted August 30, 2007 preg_replace('/\s+/', '', $content); will cover it as long as Unicode is not involved. Link to comment https://forums.phpfreaks.com/topic/67365-solved-remove-whitespace/#findComment-337976 Share on other sites More sharing options...
Jessica Posted August 30, 2007 Share Posted August 30, 2007 I think you'll have to remove each one using str_replace. Link to comment https://forums.phpfreaks.com/topic/67365-solved-remove-whitespace/#findComment-337977 Share on other sites More sharing options...
pocobueno1388 Posted August 30, 2007 Share Posted August 30, 2007 This should give you what you want. <?php $str = "There should be no spaces"; $str = str_replace(array("\n", "\r", "\t", " "), '', $str); echo $str; ?> Link to comment https://forums.phpfreaks.com/topic/67365-solved-remove-whitespace/#findComment-337985 Share on other sites More sharing options...
curt22 Posted August 30, 2007 Author Share Posted August 30, 2007 Thanks pocobueno1388. Link to comment https://forums.phpfreaks.com/topic/67365-solved-remove-whitespace/#findComment-337990 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.