[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Convert CamelCase (or Proper Case) to Underscore lower case

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

649 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