Jump to content

str_replace Question?


Guest

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
https://forums.phpfreaks.com/topic/272749-str_replace-question/
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?

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.