convert to kebab case

    0

    10

    jvitstring

    echo convertToKebabCase("studlyCase String xxx");

    // result: studly-case-string-xxx

    Shortcut: kebab

    /**
    * 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;
    }
    
    
    /**
    * Convert a string to kebab case.
    *
    * @param  string  $value
    * @return string
    */
    function convertToKebabCase($value)
    {
      return convertToSnakeCase($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.