Jump to content

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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.