Solved

Getting rid of duplicate punctuation

Posted on 2006-11-30
3
234 Views
Last Modified: 2006-11-30
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.
0
Comment
Question by:hankknight
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
3 Comments
 
LVL 13

Expert Comment

by:rhickmott
ID: 18047820
$my_string     =       str_replace(array(",,","  ","--",".."), array(","," ","-","."), $my_string);
0
 
LVL 13

Expert Comment

by:rhickmott
ID: 18047848
Sorry that should be

$my_string     =       preg_replace(array("/,+/","/ +/","/-+/","/\.+/"), array(","," ","-","."), $my_string);
0
 
LVL 13

Accepted Solution

by:
rhickmott earned 500 total points
ID: 18047897
                   $my_string    =    "                   Hello--               this is a test,, and only a test........................";
                    $my_string    =    preg_replace(array("/,+/","/ +/","/-+/","/\.+/"), array(","," ","-","."), $my_string);
                   
                    // Outputs on php 5.2.0
                    Hello- this is a test, and only a test.

( Sorry to spam your question :) )
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question