RE: [PHP] ucwords Except 'The' 'And' etc?
| From: | Mark Maggelet | Date: | Mon, 13 Aug 2001 19:52:12 +0000 |
| Subject: | RE: [PHP] ucwords Except 'The' 'And' etc? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-62492@lists.php.net to get a copy of this message | ||
>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