Jump to content

how to replace spaces between words in commas


doforumda

Recommended Posts

$string = "first  second third";

echo preg_replace('/[ ]+/', ',', ucwords($string));

//Output: First,Second,Third

great thats working thanks

 

now what if there is string with only commas between words in that string so can we capital first letter of each word after comma. the above example works but it first remove space and capitalize first letter

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.