Regular expression

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
PhpDog
Forum Commoner
Posts: 58
Joined: Mon Jan 14, 2008 10:23 am

Regular expression

Post 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).
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Re: Regular expression

Post by JAM »

Dunno about regular expression, but this seems easier...

Code: Select all

   $word = 'Print_Paragraph_1';
    $field_name = str_replace('_', ' ', ucwords(strtolower($word))).':';
PhpDog
Forum Commoner
Posts: 58
Joined: Mon Jan 14, 2008 10:23 am

Re: Regular expression

Post by PhpDog »

Yes, JAM, that is easier. Many thanks for your reply.
Post Reply