Re: replacing multiple spaces with one

From: Date: Mon, 15 Jul 2002 16:33:04 +0000
Subject: Re: replacing multiple spaces with one
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-107726@lists.php.net to get a copy of this message
Hellorgh !! $ArticleText = ereg_replace("[[:space:]].*", " ", $ArticleText); Should be fine... But AFAIK, using preg_replace should be faster, but I don't know the exact syntax to solve your probem :-( -- Nayco ----- Original Message ----- From: David Russell <DavidR@BarloworldOptimus.com> To: php-general <php-general@lists.php.net> Sent: Monday, July 15, 2002 6:15 PM Subject: [PHP] replacing multiple spaces with one > Hi all > > (easy one - I think) > > I need to replace all instances of multiple spaces in a string with a > single space. > > I tries the following: > $ArticleText = str_replace(' ', ' ', $ArticleText); > but if I have four spaces, I am left with two - this is wrong... > > I am sure that I am really looking for a ereg_replace or preg_replace, > but having no c/perl programming background, I do not know either perl > or standard regex syntax. > > Could someone tell me what the correct ereg/preg expression for this > would be? I would also like a pointer to regex syntax, if someone knows > offhand. > > Thanks > > David R > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.general (#107726) next »