brian914 Posted May 25, 2011 Share Posted May 25, 2011 I have the following function, which takes a string with commas in it and attempts remove those commas. The way I have it here is that I use explode to take out the commas, which makes an array, and then iterate through that array to put a string back together without the commas. function tags_to_sort_by( $sortMeta ) { $sortByArray = explode(",", $sortMeta); $sortByCount = count($sortByArray); for ($i = 0; $i < $sortByCount; $i++) { $sortByString += $sortByArray[$i]; } return $sortByString; } What does not work is the following line: $sortByString += $sortByArray[$i]; Somehow that outputs a 0, which I don't understand. It should output something like: arrayItem1 arrayItem2 array3 etc. My question is if there either is an easier way to remove the commas from the original string or what I am doing wrong in this line: $sortByString += $sortByArray[$i]; // I am trying to concatenate each part of the array back into the string. Thanks a lot for help with this! Link to comment https://forums.phpfreaks.com/topic/237384-removing-commas-from-a-string-and-keeping-it-a-string/ Share on other sites More sharing options...
gizmola Posted May 25, 2011 Share Posted May 25, 2011 Yes there is an easier way. str_replace Link to comment https://forums.phpfreaks.com/topic/237384-removing-commas-from-a-string-and-keeping-it-a-string/#findComment-1219830 Share on other sites More sharing options...
brian914 Posted May 25, 2011 Author Share Posted May 25, 2011 Perfect! Thank you so much! Link to comment https://forums.phpfreaks.com/topic/237384-removing-commas-from-a-string-and-keeping-it-a-string/#findComment-1219835 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.