In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Henry) wrote:

> I'm looking for a simple was to correct a list of proper nouns given all in
> lower case!
> 
> For example
> 
> given $string="london paris rome";
> 
> I would like "London Paris Rome".
> 
> However there is one cavet; if the word already has a captital anywhere in
> it, it should be left alone!!!
> 
> Is there a soultion using regular expressions?

Yes.  The topics you'll want to look at (in the PCRE chapter of the manual) 
are: case-sensitivity, character classes, capturing subpatterns, and the 
documentation for preg_replace_callback().  One of the things you'll need 
to do is define for yourself what constitutes a "word" for your purposes.  
Does a single letter word get counted as a "word" (i.e. "i")?  Is there any 
non-alphabet character that can validly appear within the thing you call a 
word (i.e. "hi-fi", "mst3k")?  This is why there's no single ready-made 
solution.

> Also is there one for removing multiple spaces?
> 
> i..e given "A   B C D E" it would give "A B C D E".

Yes.  Again, character classes will be your friend, as will preg_replace().  
Just decide which of the whitespace characters you mean to include in that 
definition of "multiple spaces"...

-- 
CC

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

Reply via email to