Oihana PHP

hyphenate.php

Table of Contents

Functions

hyphenate()  : string
Converts a camelCase or PascalCase string to a hyphenated (kebab-case) string.

Functions

hyphenate()

Converts a camelCase or PascalCase string to a hyphenated (kebab-case) string.

hyphenate(string|null $source) : string

This is useful for transforming class names or identifiers into URL- or CSS-friendly format.

Examples:

  • "helloWorld" → "hello-world"
  • "HTMLParser" → "html-parser"
  • "aTestString" → "a-test-string"
Parameters
$source : string|null

The camelCase or PascalCase string to convert.

Tags
example
echo hyphenate("helloWorld");
// Output: "hello-world"

echo hyphenate("SimpleXMLParser");
// Output: "simple-xml-parser"

echo hyphenate("AString");
// Output: "a-string"

echo hyphenate(null);
// Output: ""
author

Marc Alcaraz (ekameleon)

since
1.0.0
Return values
string

The hyphenated (kebab-case) string.


        
On this page

Search results