RE: [PHP] ucwords Except 'The' 'And' etc?
| From: | Jeff Oien | Date: | Mon, 13 Aug 2001 21:09:51 +0000 |
| Subject: | RE: [PHP] ucwords Except 'The' 'And' etc? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-62503@lists.php.net to get a copy of this message | ||
Fabulous. Thanks to Steve and Mark. Exactly what I needed.
Jeff Oien
> >Something like this, perhaps (untested):
>
> I needed this too so I just tested it.
>
> >function smart_ucwords($String)
> >{
> >
> > $ExceptionList = array('the', 'an', 'a'); # should all be in
> >
> >lowercase
> >
> > $String = ucwords(strtolower(ltrim($String))); # LINE A
> >
> > foreach ($ExceptionList as $Word)
> > {
> > $String = eregi_replace("[[:space:]]+$Word[[:space:]]+",
> >$Word, $String);
> > }
>
>
> this line should be more like:
> $String = eregi_replace("([[:space:]]+)".$Word."([[:space:]]+)",
> "\\1".$Word."\\2", $String);
>
> > return $String; # LINE B
> >
> >}
>
> thanks!
> - Mark
>