大写"_"后面的字符, 三种方法及其时间比较
2017-06-20 17:11
246 查看
$str = 'str_ab ae_dfe';
$time1 = microtime();
for($i = 0; $i<1000; $i++){
str_replace(
array(' ', '##'),
array('', ' '),
lcfirst(ucwords(str_replace(
array(' ', '_'),
array('##', ' '),
$str
)))
);
}
$time2 = microtime();
$str = 'str_ab ae_dfe';
for($i = 0; $i<1000; $i++){
$str = explode('_', $str);
foreach($str as $k=>&$v){
if($k == 0)
continue;
$v = ucfirst($v);
}
$str = implode('', $str);
}
$time3 = microtime();
echo $time2 - $time1;
echo '<br>';
echo $time3 - $time2;
echo '<br>';
$str = 'str_ab ae_dfe';
$t = microtime();
for($i = 0; $i < 1000; $i++){
preg_replace_callback('|_(\w)|', function($matches){
return strtoupper($matches[0]);
}, $str);
}
echo microtime()-$t;
exit;
$str = explode('_', $str);
foreach($str as $k=>&$v){
if($k == 0)
continue;
$v = ucfirst($v);
}
$str = implode('', $str);
echo $str;exit;
echo preg_replace('/_([a-z])/',strtoupper('\\1'),$str);
exit;
$arr = explode(' ', $str);
foreach($arr as &$v){
$vv = ucwords(str_replace(array('-', '_'), ' ', $v));
$v = str_replace(' ','',lcfirst($vv));
}
$str = implode(' ', $arr);
echo $str;
$time1 = microtime();
for($i = 0; $i<1000; $i++){
str_replace(
array(' ', '##'),
array('', ' '),
lcfirst(ucwords(str_replace(
array(' ', '_'),
array('##', ' '),
$str
)))
);
}
$time2 = microtime();
$str = 'str_ab ae_dfe';
for($i = 0; $i<1000; $i++){
$str = explode('_', $str);
foreach($str as $k=>&$v){
if($k == 0)
continue;
$v = ucfirst($v);
}
$str = implode('', $str);
}
$time3 = microtime();
echo $time2 - $time1;
echo '<br>';
echo $time3 - $time2;
echo '<br>';
$str = 'str_ab ae_dfe';
$t = microtime();
for($i = 0; $i < 1000; $i++){
preg_replace_callback('|_(\w)|', function($matches){
return strtoupper($matches[0]);
}, $str);
}
echo microtime()-$t;
exit;
$str = explode('_', $str);
foreach($str as $k=>&$v){
if($k == 0)
continue;
$v = ucfirst($v);
}
$str = implode('', $str);
echo $str;exit;
echo preg_replace('/_([a-z])/',strtoupper('\\1'),$str);
exit;
$arr = explode(' ', $str);
foreach($arr as &$v){
$vv = ucwords(str_replace(array('-', '_'), ' ', $v));
$v = str_replace(' ','',lcfirst($vv));
}
$str = implode(' ', $arr);
echo $str;
相关文章推荐
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#比较时间大小三种方法
- NET实用教程之C#三种比较时间大小、比较日期的方法
- C#里面比较时间大小三种方法
- (转)C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- ASP:用ADO连接数据库的三种方法及其性能比较
- C#里面比较时间大小三种方法
- (转)C#里面比较时间大小三种方法
- C#判断字符串是否为空的三种方法及其比较
- C#里面比较时间大小三种方法
- 代码详解C#比较时间的三种方法
- C#里面比较时间大小三种方法