preg-replace-在php中将下划线转换为camelcaps


preg replace - convert underscore to camelcaps in php

我想在php中将下划线字符串转换为camelcase字符串。使用preg_replace如何做到这一点?

例如:offer_listofferList

可以在正则表达式上使用/e修饰符,如下所示:

preg_replace("/_([a-zA-Z])/e", 'strtoupper("$1")', "camel_case_word")

无preg:

 /**
 * Converts underscore string into camel
 * @param   string    $str
 * @return  string 
 */
public static function underToCamel($str){
    return   'lcfirst(str_replace(' ', "", ucwords(strtr($str, '_-', ' '))));
}