SomeoneS SomeoneS - 23 days ago 8
PHP Question

Split sentence into words separated with commas

i have one sentence saved in database field , an i want to break it in words, but that words needs to be separated by coma, like this:

This, is, test, text


I tried something with explode() but it didnt do the work.

Answer

You could do

$text = "This is test text";
echo str_replace (" ", ", ", $text); // This, is, test, text
Comments