Page 1 of 1

Quick and dirty regex question

Posted: Wed Feb 22, 2012 4:20 am
by eazyGen
Hi guys,

I would normally research this myself, but I am in a hurry just now.

My question is - how would I take a string like:

"Customer Name"

or

"Product Cost Price"

and produce a result where all upper case letters are made lower case and all spaces replaced by under-scores. Like this:

"Customer Name" would become "customer_name", and

"Product Cost Price" would become "product_cost_price"

Many thanks for any swift help,

S

Re: Quick and dirty regex question

Posted: Wed Feb 22, 2012 5:36 am
by Celauran
Not regex, but this should do the job:

Code: Select all

strtolower(str_replace(' ', '_', $string))

Re: Quick and dirty regex question

Posted: Thu Feb 23, 2012 7:53 pm
by eazyGen
Celauran wrote:Not regex, but this should do the job:

Code: Select all

strtolower(str_replace(' ', '_', $string))
Thank you.

Sorry to appear lazy, but I was in a mad rush.

S