Created
March 7, 2025 22:11
-
-
Save mikeoberdick/9a59df9ce0ffb909e91f282ece11dd60 to your computer and use it in GitHub Desktop.
Create a slug using a function to use within a php template
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 spaces 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