Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Converting all underscore connected letters to uppercase in php

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.52k
    Comment on it

    In PHP if we want to replace all underscore connected letters to upper case then we can use the php function called "preg_replace_callback" .

    For example if we have string "kp_o_zmq_k" then the output becomes "kpOZmqK".

    See the example below:

    $ptn = "/_[a-z]?/";
    $str = "kp_o_zmq_k";
    $result = preg_replace_callback($ptn,"callbackhandler",$str);
    // print the result
    echo $result;
    
    function callbackhandler($matches) {
        return strtoupper(ltrim($matches[0], "_"));
    }

    Hope this helps!

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: