lokie538 Posted January 17, 2009 Share Posted January 17, 2009 Hi, I have to find how to remove all the white spaces and line breaks so it is just a string. For instance the output should be "cooroy, cooroy mountain, lake mcdonald, tinbeerwah" This is the output I have at the moment: COOROY, COOROY MOUNTAIN, LAKE MACDONALD, TINBEERWAH Ive tried to string replace " " with "" but there are still all the line breaks which I need to be removed. There is probably a simplified way to do this? Any suggestion guys? Ive tried looking at nl2br( but that hasn't worked either. Link to comment https://forums.phpfreaks.com/topic/141211-removing-white-spaces-and-line-breaks/ Share on other sites More sharing options...
dawsba Posted January 17, 2009 Share Posted January 17, 2009 off the top of my head for($i=0;$i<=strlen($string);$i++) { if(preg_match("/^([a-z0-9])/i",substr($string,$i,1)){$new_string .= substring($string,$i,1);} } i have no doubt theres a better way of doing it but i just woke up Link to comment https://forums.phpfreaks.com/topic/141211-removing-white-spaces-and-line-breaks/#findComment-739085 Share on other sites More sharing options...
dawsba Posted January 17, 2009 Share Posted January 17, 2009 sorry, revised for($i=0;$i<=strlen($string);$i++) { if(preg_match("/^([a-z0-9\,])/i",substr($string,$i,1))){$new_string .= substr($string,$i,1);} } echo $new_string; ?> Link to comment https://forums.phpfreaks.com/topic/141211-removing-white-spaces-and-line-breaks/#findComment-739087 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.