Home > Backend Development > PHP Tutorial > PHP converts uppercase names into underscores to separate names, php underscore_PHP tutorial

PHP converts uppercase names into underscores to separate names, php underscore_PHP tutorial

WBOY
Release: 2016-07-13 09:56:00
Original
992 people have browsed it

php converts uppercase names into underscores to separate names, php underscores

Sometimes it is necessary to convert uppercase letters in a string to _ lowercase, which will happen when naming variables If you encounter this kind of problem, just go to the code:

$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);
}
Copy after login

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/990552.htmlTechArticlephp converts uppercase names into underscores to separate names. php underscores sometimes need to convert uppercase letters in a string into _ Lowercase, you will encounter this problem when naming variables...
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template