Solved

Convert CamelCase (or Proper Case) to Underscore lower case

Posted on 2008-06-15
1
4,075 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
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now