字符串开头小写变大写

有这样的字符串:“get_post_title”,要变成如此字符 "GetPostTitle"

$s = 'get_post_title';

echo preg_replace('/(^|_)(\w)/e', 'strtoupper("$2")', $s);

或则 

preg_replace_callback("/(^|_)(\w)/",function($r){return strtoupper($r[2])},$s)

猜你喜欢

转载自blog.csdn.net/TottyAndBaty/article/details/83829201
今日推荐