Jump to content

[SOLVED] Removing extra white space


joshblue

Recommended Posts

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

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.