[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Regular Expressions: Perl vs PHP



Hi! I have a PHP3 script that accepts a file uploaded. I am using
split() to parse the space-delimited file. An undefined amount of
whitespace seperates the fields, so I am trying to use regexps to
replace any contingous whitespace with one space. According to 
a Perl book I have on hand, " +" (w/out quotes) will match 1..n 
number of spaces. Thus, "perl -pe 's/ +/ /gi' < inputfile" does
exactly what I want. 

For some reason,  "sed 's/ +/ /g' inputfile" does not do the
same thing, and ereg_replace(" +", " ", $line), where $line is 
a line read from the file, does not do the same thing. What am 
I missing here? I knew that Perl 5 added some regexp functions,
but I thought that the + operator was pretty basic. Someone 
please enlighten me.
-- 
Stephen Pitts
smpitts@midsouth.rr.com
webmaster - http://www.mschess.org


Reply to: