-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.php
32 lines (31 loc) · 1.03 KB
/
helper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
if (!function_exists('camelize')) {
/**
* 下划线转驼峰
* 思路:
* step1.原字符串转小写,原字符串中的分隔符用空格替换,在字符串开头加上分隔符
* step2.将字符串中每个单词的首字母转换为大写,再去空格,去字符串首部附加的分隔符.
* @param $unCamelizeWords
* @param string $separator
* @return string
*/
function camelize($unCamelizeWords, $separator = '_')
{
$unCamelizeWords = $separator . str_replace($separator, " ", strtolower($unCamelizeWords));
return str_replace(" ", "", ucwords(ltrim($unCamelizeWords, $separator)));
}
}
if (!function_exists('to_under_score')) {
/**
* 驼峰命名转下划线命名
* @param $str
* @return string
*/
function to_under_score($str)
{
$dstr = preg_replace_callback('/([A-Z]+)/', function ($matchs) {
return '_' . strtolower($matchs[0]);
}, $str);
return trim(preg_replace('/_{2,}/', '_', $dstr), '_');
}
}