Php converts an uppercase name to an underline to separate the names
This article mainly introduces how php converts an uppercase name to an underscore (_), and explains some naming methods that are not used to an uppercase style, such as Pascal name and camper name, for more information, see
Sometimes you need to convert the uppercase letters in a string to the lowercase letters (_ +). This problem occurs when naming variables. You can directly run the following code:
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 |
$ Name = 'apppromozhongqiu2014activestatusselector ';
Echo cc_format ($ name );
Function cc_format ($ name ){
$ Temp_array = array ();
For ($ I = 0; $ I <strlen ($ name); $ I ++ ){
$ Ascii_code = ord ($ name [$ I]);
If ($ ascii_code >=65 & $ ascii_code <= 90 ){
If ($ I = 0 ){
$ Temp_array [] = chr ($ ascii_code + 32 );
} Else {
$ Temp_array [] = '_'. chr ($ ascii_code + 32 );
}
} Else {
$ Temp_array [] = $ name [$ I];
}
}
Return implode ('', $ temp_array );
}
|