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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 09:55:58
Original
956 people have browsed it

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...
Related labels:
php
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template