[PHP] replacing multiple spaces with one

2002-07-15 Thread David Russell

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




Re: [PHP] replacing multiple spaces with one

2002-07-15 Thread nico_free

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 [EMAIL PROTECTED]
To: php-general [EMAIL PROTECTED]
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




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] replacing multiple spaces with one

2002-07-15 Thread Jason Wong

On Tuesday 16 July 2002 00:15, David Russell wrote:
 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?

  $ArticleText = preg_replace('/ +/', ' ', $ArticleText);

This replaces instances of one or more space with a single space.

 I would also like a pointer to regex syntax, if someone knows
 offhand.

The manual?

-- 
Jason Wong - Gremlins Associates - www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *

/*
Standards are crucial.  And the best thing about standards is: there are
so many to choose from!
*/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php