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

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.