So I want to remove space between tags. The tags are seperated by comma. But I don't want to remove space between words just right after the commas.
cats, funny cats, cute cats, funny
cats,funny cats,cute cats,funny
I want them ready for insertion into database.
This is what I have come up with:
<?php $tags = 'cats, funny, hair cut, funny hair cut'; $result = str_replace(', ', ',', $tags); echo $tags . '<br />'; echo $result; ?>
But there might be a problem when the user enters more than one space after the comma. How can I replace it even if the user enters more than one space after a comma. Do I use regular expression? How can I use it?