Home >Backend Development >PHP Tutorial >PHP converts uppercase names into underscore-separated names_PHP tutorial

PHP converts uppercase names into underscore-separated names_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:55:58932browse

php converts uppercase names into underscore-separated names

This article mainly introduces php to convert uppercase names into underscore-separated names. This article explains some names that are not used to the capital style. Methods such as Pascal naming and camel case naming method for conversion, friends in need can refer to it

Sometimes it is necessary to convert the uppercase characters in a string to _ lowercase. This problem will be encountered when naming variables. Go directly to the 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

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

}

1

2

34 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 <= 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); }

http://www.bkjia.com/PHPjc/990997.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/990997.htmlTechArticlephp converts uppercase names to underscores to separate names. This article mainly introduces php to convert uppercase names to underscores to separate names. , this article explains the naming methods for some people who are not used to capital style...
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