In my bio information users sometimes input sentences without using the proper spacing, like this:
$bio = 'Hey there,I'm Tom!And I'm 25';
I use preg replace to fix the commas:
$bio = str_replace(",", ", ", $bio);
Which echo’s:
$bio = 'Hey there, I'm Tom!And I'm 25';
How do I do this for all the other punctuation signs except ‘ (from I’m) ?
Any ideas?
you can use preg_replace with arrays.
first create an array signs to replace like:
than another array with the replacements
now use both arrays with preg_replace:
to be sure the next sign is’nt already a whitspace you could use a more complex regular expression for each character like this one:
http://php.net/manual/de/function.preg-replace.php