Solved

Getting rid of duplicate punctuation

Posted on 2006-11-30
3
235 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
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…

617 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