SomeoneS SomeoneS - 3 months ago 28
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.


You could do

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