Jump to content

str_replace Question?


scm22ri

Recommended Posts

Hi Everyone,

 

I'm interested in replacing white space after a certain set of characters. The characters aren't a set number, they change depending on what the user types into the form. How would I go about doing that with str_replace? Is it even possible with str_replace or perhaps another function?

 

$value = New York (I don't want to replace the white space between the w and Y but I do want to replace the white space after k if a user uses the space key)

 

$value = str_replace(' ', '', $value);

 

Thanks Everyone

Link to comment
Share on other sites

The "replace the white space after k" sounds like you want to remove it when it's at the end of the string (and maybe the beginning too). trim will do exactly that.

 

Otherwise str_replace() isn't powerful enough and you need regular expressions. Exactly when should spaces be removed?

Link to comment
Share on other sites

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.