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 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; 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! 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
Archived
This topic is now archived and is closed to further replies.