yosii Posted September 3, 2009 Share Posted September 3, 2009 i have this string --h5jd456jc2xdw33cx3ccc -- i want to delete the spase between "c" and "-" how can i do this for all the string like that for example --h5jsdfsddscdcdfvdfvdfvc -- --h5jd45ddf444444rrr4443ccc -- --h5vvvvvvv3rvvvvvvvvggggggg3ccc -- i just dont want that in my string will be space thank Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted September 3, 2009 Share Posted September 3, 2009 $strWithSpace = "adhfaji dafhadkfh 899afd9afyh"; $newString = str_replace(" ", '', $strWithSpace); echo $newString; Quote Link to comment Share on other sites More sharing options...
bundyxc Posted September 3, 2009 Share Posted September 3, 2009 Or if your string is supposed to have string in other places, and you only want them removed when next to the trailing hyphen, you would use this: $strWithSpace = '--abc d e f ghijklmno --'; $newString = str_replace(' --', '', $strWithSpace); echo $newString; //Returns --abc d e f ghijklmno-- Quote Link to comment Share on other sites More sharing options...
yosii Posted September 3, 2009 Author Share Posted September 3, 2009 not work!!!! both of the way Quote Link to comment Share on other sites More sharing options...
akitchin Posted September 3, 2009 Share Posted September 3, 2009 Or if your string is supposed to have string in other places, and you only want them removed when next to the trailing hyphen, you would use this: $strWithSpace = '--abc d e f ghijklmno --'; $newString = str_replace(' --', '', $strWithSpace); echo $newString; //Returns --abc d e f ghijklmno-- actually, it will return: --abc d e f ghijklmno because you've replaced the entire " --" string with an empty one. you'd need: $newString = str_replace(' --', '--', $strWithSpace); EDIT: yosii, in future it would help to know exactly HOW neither of those work. what are you putting in, and what is coming out? my answer is still only a guess, because you haven't provided any information. Quote Link to comment Share on other sites More sharing options...
bundyxc Posted September 4, 2009 Share Posted September 4, 2009 Oh, duh. Thanks akitchin. And I agree. Tell us what you need, and actually try to do it yourself. Quote Link to comment 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.