jb60606 Posted June 2, 2007 Share Posted June 2, 2007 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 https://forums.phpfreaks.com/topic/53980-cant-remove-spaces-from-string-extracted-from-array/ Share on other sites More sharing options...
taith Posted June 2, 2007 Share Posted June 2, 2007 $arr = file('data/symbols.dat'); foreach($arr as $k=>$v){ $arr[$k]=trim($v); } $sym = implode('+', $arr); Link to comment https://forums.phpfreaks.com/topic/53980-cant-remove-spaces-from-string-extracted-from-array/#findComment-266842 Share on other sites More sharing options...
jb60606 Posted June 2, 2007 Author Share Posted June 2, 2007 works perfectly! Thanks a million. Link to comment https://forums.phpfreaks.com/topic/53980-cant-remove-spaces-from-string-extracted-from-array/#findComment-266850 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.