Home  >  Article  >  php教程  >  php把大写命名转换成下划线分割命名

php把大写命名转换成下划线分割命名

WBOY
WBOYOriginal
2016-06-13 09:05:48849browse

php把大写命名转换成下划线分割命名

   这篇文章主要介绍了php把大写命名转换成下划线分割命名,本文讲解对一些不习惯大写风格的命名方法如帕斯卡命名、驼峰命名法进行转换的方法,需要的朋友可以参考下

  有时候需要把一个字符串中的大写转换成 _+小写的方式,在变量命名的时候会碰到这种问题,直接上代码:

  ?

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

$ascii_code = ord($name[$i]);

if($ascii_code >= 65 && $ascii_code

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);

}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn