<?php
// 请写一个函数 实现以下功能
// 字符串open_door转换成OpenDoor、make_by_id转换成MakeById
// 方式一
function str_ucwords($str){
$strArr = explode('_', $str);
$str = implode(' ', $strArr);
$str = implode('', explode(' ', ucwords($str)));
return $str;
}
// 方式二
function str_ucwords($str){
$expStr = explode('_', $str);
$retStr = '';
for($i=0;$i<count($expStr);$i++){
$retStr .= ucwords($expStr[$i]);
}
return $retStr;
}
// 方式三
function str_ucwords($str){
return str_replace(' ','', ucwords(str_replace('_',' ',$str)));
}
$ret = str_ucwords('open_door');
print_r($ret); // OpenDoor