text_to_id
— Convert a word or phrase to a valid HTML ID.
Summary
- text_to_id($text, $prepend = null, $delimiter = '-')
Convert a word or phrase to a valid HTML ID.
For example: ‘Foo Bar’ becomes ‘foo-bar’.
This function converts to lowercase, replaces whitespace with hyphens, removes all non-alphanumerics, removes leading or trailing delimiters, and optionally prepends a piece of text.
- Parameters:
$text (
string
) – The text to convert$prepend (
string
) – Another string to prepend to the ID$delimiter (
string
) – The delimiter to use (- by default)
- Returns:
string