I have a string (not an array, this is loading words stored on one line), and I would like to put a comma after each word, although not put it after the last word. I have:
echo str_replace(' ', ', ', $stilltodo);
but for some reason adds a space before the comma (and after too, but that's right), and also one at the end. How can I change it to work as I want.
Example string "base"
French History Maths Physics Spanish Chemistry Biology English DT Maths History DT Spanish English French RS
Current output example with code above
French , History , Maths , Physics , Spanish , Chemistry , Biology , English , DT , Maths , History , DT , Spanish , English , French , RS ,
source share