www.webdeveloper.com
Results 1 to 2 of 2

Thread: Is there a better way to do this?

  1. #1
    Join Date
    Feb 2012
    Location
    Tallahassee, FL
    Posts
    280

    Is there a better way to do this?

    I dont see myself using this elsewhere in the application so I don't want to make it a stand alone function. I feel like there is probably a preg_replace that would do what I want more efficiently.

    PHP Code:
    //This makes $col = "overviewContentEditable";  
    $col str_replace(" ","",lcfirst(ucwords(str_replace("_"," ","overview_content_editable")))); 
    It does exactly what I need it too, just wondering if there was a faster way.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,529
    Maybe (untested):
    PHP Code:
    $result preg_replace_callback(
        
    '/_+([^_])/',
        function(
    $matches) {
            return 
    strtoupper($matches[1]);
        },
        
    $inputString
    ); 
    As to whether that's actually more efficient processing-wise, you'd have to do some metering to find out. (Regex functions in general tend to be less efficient than comparable built-in string functions, but in a more complex case like this, the only way to tell would be to try it and measure it.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles