Solved

Convert CamelCase (or Proper Case) to Underscore lower case

Posted on 2008-06-15
1
4,105 Views
Last Modified: 2011-09-20
I need to convert a CamelCase (or ProperCase)  string into a underscored lower case string.

Bascially, I need to take something like this:

test_ThisIsATest;

and make a new string come out like this:
test_this_is_a_test;

Anyone know of any easy way to do this in PHP?

Thanks!
0
Comment
Question by:swhitlow
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

by:
swhitlow earned 0 total points
ID: 21790139
I ended up working this one out myself. Here is the function I used just in case anyone else might need it:

function underscore($word)
          {
              static $_cached;
              if(!isset($_cached[$word])){
                  $_cached[$word] = strtolower(preg_replace(
                  array('/[^A-Z^a-z^0-9^\/]+/','/([a-z\d])([A-Z])/','/([A-Z]+)([A-Z][a-z])/'),
                  array('_','\1_\2','\1_\2'), $word));
              }
              return $_cached[$word];
          }
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question