Jump to content

how to delete space??


yosii

Recommended Posts

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

Link to comment
Share on other sites

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--

Link to comment
Share on other sites

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.

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.