?
Solved

Convert CamelCase (or Proper Case) to Underscore lower case

Posted on 2008-06-15
1
Medium Priority
?
4,120 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

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…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
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.
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 …
Suggested Courses

777 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