[thelist] Title-case regex in PHP?

jsWalter jsWalter at torres.ws
Sat Sep 27 17:56:32 CDT 2003


> -----Original Message-----
> From: thelist-bounces at lists.evolt.org
> [mailto:thelist-bounces at lists.evolt.org]On Behalf Of Kelly Hallman
> Sent: Saturday, September 27, 2003 4:10 PM
> To: thelist at lists.evolt.org
> Subject: [thelist] Title-case regex in PHP?
> 
> 
> In perl, this does what I want:
> $x =~ s/(\w)(\w+)/\U\1\L\2/g;
> 
> However, in PHP, this does not work (inserts \U and \L's):
> preg_replace("/(\w)(\w+)/","\U$1\L$2",$x);
> 
> Any ideas?

Well, how about a non-RegEx way?

   $string = "this IS a StinG THAT has Many Camel CasE";
   $string = strtolower($string); 
   $string = ucwords($string); 

   echo $string;

This does work, I took my time [;)], this time!

Walter




More information about the thelist mailing list