true...he didn't mention newlines though so i left those out...also, "since PHP 4.0.4 $n [meaning $1], being the preferred one." you also don't need double quotes and since + means 1 or more, i'd save myself some typing $input = preg_replace('/(\s|\n)+/',"$1",$input); of course since you're now matching and replacing it'll take longer than a straight substitution, although i doubt the files you're scanning are big enough to notice
jack -----Original Message----- From: liljim [mailto:[EMAIL PROTECTED]] Sent: Wednesday, December 05, 2001 5:18 AM To: [EMAIL PROTECTED] Subject: Re: [PHP] Reg ex help-Removing extra blank spaces before HTML output Hello, The example Jack gave you will clear up spaces well, though to get both newlines and spaces into one: $input = preg_replace("/([ ]|\n){1,}/", "\\1", $input); James "Jack Dempsey" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > $text = preg_replace('|\s+|',' ',$text); > > > -----Original Message----- > From: Ken [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, December 05, 2001 2:06 AM > To: PHP list > Subject: [PHP] Reg ex help-Removing extra blank spaces before HTML > output > > > I want to remove all superfluous blank spaces before I sent my HTML output, > to make the output smaller. > > So I'd like to take $input, replace any number of blank space or newlines > that are consecutive and replace them with a single blank. > > I.e. I will list a blank space as b and a newline as n: > > If input is: bbbbbTEXTHEREbbbnnnbnMOREbEVENMORE > Then output should be: bTEXTHEREbMOREbEVENMORE > > I imagine this would be handled by a simple regular expression call, but I'm > no pro with them yet. > > Any help? > > Thanks, > Ken > [EMAIL PROTECTED] > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]