Jump to content

cant remove spaces from string extracted from array


jb60606

Recommended Posts

I have a file, containing stock symbols:

 

symbols.dat

IBM

SIRI

GOOG

AMD

INTC

MSFT

DELL

 

I need to extract all symbols from the file, and turn them into a string, each being separated by a "+".

 

IBM+SIRI+GOOG+AMD+INTC+MSFT+DELL

 

I do this with the following code:

 

$arr = file('data/symbols.dat'); //extract file contents into array
$sym = implode('+', $arr); //make array a string, separate each array element with a "+"

 

The end result is the string, though, there is a space after each symbol, before the "+"

 

IBM +SIRI +GOOG +AMD +INTC +MSFT +DELL

 

 

Does anyone know how I can get rid of the spaces? I've tried using str_replace, rtrim, etc, though either I'm using them in the wrong order, or they just doesn't work. The string is used in a URL, so there can be no spaces.

 

Thanks

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.