scm22ri Posted January 6, 2013 Share Posted January 6, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/272749-str_replace-question/ Share on other sites More sharing options...
requinix Posted January 6, 2013 Share Posted January 6, 2013 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? Quote Link to comment https://forums.phpfreaks.com/topic/272749-str_replace-question/#findComment-1403545 Share on other sites More sharing options...
scm22ri Posted January 7, 2013 Author Share Posted January 7, 2013 Thanks requinix, php function trim did the trick! Quote Link to comment https://forums.phpfreaks.com/topic/272749-str_replace-question/#findComment-1403984 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.