hankknight
asked on
Getting rid of duplicate punctuation
Hello,
I want to remove all duplicates of spaces, dashes, periods and commas.
So
Hello-- this is a test,, and only a test...................... ..
Should become
Hello- this is a test, and only a test.
I want to remove all duplicates of spaces, dashes, periods and commas.
So
Hello-- this is a test,, and only a test......................
Should become
Hello- this is a test, and only a test.
$my_string = str_replace(array(",,"," ","--",".."), array(","," ","-","."), $my_string);
Sorry that should be
$my_string = preg_replace(array("/,+/", "/ +/","/-+/","/\.+/"), array(","," ","-","."), $my_string);
$my_string = preg_replace(array("/,+/",
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.