joshblue Posted September 1, 2009 Share Posted September 1, 2009 I'm trying to solve this one... I made a script where they would remove some specials characters like: JOHN & JOHN will be JOHN JOHN But the problem is, it turns out that there still an extra white space between it.. JOHN JOHN <- 2 spaces in between the words So can I clean-up and remove the extra space? Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/172658-solved-removing-extra-white-space/ Share on other sites More sharing options...
MadTechie Posted September 1, 2009 Share Posted September 1, 2009 try this *untested* $data = " the quick red fox jumped over the lazy dog "; $data = trim(preg_replace('/(\s)(\1+)/im', '\1', $data)); echo $data; Quote Link to comment https://forums.phpfreaks.com/topic/172658-solved-removing-extra-white-space/#findComment-910092 Share on other sites More sharing options...
joshblue Posted September 1, 2009 Author Share Posted September 1, 2009 try this *untested* $data = " the quick red fox jumped over the lazy dog "; $data = trim(preg_replace('/(\s)(\1+)/im', '\1', $data)); echo $data; I think its working... Thank you very much! I was actually thought of the preg_replace() but I don't memorize the Regular Expressions to used. Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/172658-solved-removing-extra-white-space/#findComment-910099 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.