How to convert PascalCase to pascal_case?

前端 未结 30 1667
北海茫月
北海茫月 2020-11-29 16:36

If I had:

$string = \"PascalCase\";

I need

\"pascal_case\"

Does PHP offer a function for this purpose?

30条回答
  •  生来不讨喜
    2020-11-29 17:10

    Here is my contribution to a six-year-old question with god knows how many answers...

    It will convert all words in the provided string that are in camelcase to snakecase. For example "SuperSpecialAwesome and also FizBuzz καιΚάτιΑκόμα" will be converted to "super_special_awesome and also fizz_buzz και_κάτι_ακόμα".

    mb_strtolower(
        preg_replace_callback(
            '/(?

提交回复
热议问题