How to convert uppercase names to underscore separated names in php

墨辰丷
Release: 2023-03-31 14:50:01
Original
2065 people have browsed it

This article mainly introduces how PHP converts uppercase naming into underscore-separated naming. This article explains how to convert some naming methods that are not accustomed to the uppercase style, such as Pascal naming and camel case naming. Friends who need it can refer to it

Sometimes it is necessary to convert the uppercase characters in a string to _ lowercase. You will encounter this problem when naming variables. Just enter 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[] = &#39;_&#39;.chr($ascii_code + 32);
      }
    }else{
      $temp_array[] = $name[$i];
    }
  }
  return implode(&#39;&#39;,$temp_array);
}
Copy after login

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.

Related recommendations:

PHP implements the function of dynamically adding image watermarks according to the color environment

The role and usage of type prompts in PHP

PHP implements the function of capturing pictures from online albums with anti-leeching settings

The above is the detailed content of How to convert uppercase names to underscore separated names in php. For more information, please follow other related articles on the PHP Chinese website!

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