convert to snake case

    0

    11

    jvitstring
    JVIT PHP

    echo convertToSnakeCase('Hello friends');

    // result: hello_friends

    Shortcut: snake

    /**
    * Convert a string to snake case.
    *
    * @param  string  $value
    * @param  string  $delimiter
    * @return string
    */
    function convertToSnakeCase($value, $delimiter = '_')
    {
      if (!ctype_lower($value)) {
        $value = preg_replace('/\s+/u', '', ucwords($value));
    
        $value = strtolower(preg_replace('/(.)(?=[A-Z])/u', '$1' . $delimiter, $value));
      }
    
      return $value;
    }
    
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    Legal
    • Security
    • Privacy Policy
    • Code Privacy
    • Terms of Service
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.