Page 1 of 1

Regular expression

Posted: Sat Jan 26, 2008 2:17 pm
by PhpDog
I'm just starting out with regular expressions and wonder how would I go about this please:

After returning a MS SQL database field name of , say,

$field_name = "Print_Paragraph_1";

how can I use a regular expression to change this so that

$fields_name = "Print paragraph 1:"

please?

(change all letters, other than the first letter, to lower case, replace underscores with spaces and append a colon).

Re: Regular expression

Posted: Sat Jan 26, 2008 2:26 pm
by JAM
Dunno about regular expression, but this seems easier...

Code: Select all

   $word = 'Print_Paragraph_1';
    $field_name = str_replace('_', ' ', ucwords(strtolower($word))).':';

Re: Regular expression

Posted: Sat Jan 26, 2008 3:38 pm
by PhpDog
Yes, JAM, that is easier. Many thanks for your reply.