Created
October 22, 2019 13:47
-
-
Save kobus1998/1858d940698baaa1f6fc22d06d381b77 to your computer and use it in GitHub Desktop.
slugify for url, id, var etc
This file contains 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
<?php | |
function slugify($sVal, $sDelimiter = '-') | |
{ | |
$sVal = preg_replace("/[^a-zA-Z0-9_-]/", $sDelimiter, $sVal); | |
$sVal = preg_replace("/$sDelimiter{2,}/", $sDelimiter, $sVal); | |
return trim($sVal, $sDelimiter); | |
} | |
echo slugify("my company name ~ !!!!!") . "\n"; // my-company-name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment