Created
January 10, 2025 21:28
-
-
Save mikeoberdick/3bf8364c1a3c2f547405f913ba02667f to your computer and use it in GitHub Desktop.
Function to create a slug from a string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Create a slug | |
function createSlug($text) { | |
// Convert the string to lowercase | |
$lowercaseText = strtolower($text); | |
// Replace non-number/letters with hyphens | |
$slug = preg_replace('/[^a-zA-Z0-9]/', '-', $lowercaseText); | |
return $slug; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment