Created
November 9, 2016 15:13
-
-
Save Tiriel/3eb6ba728312b294c050de1efa439ba3 to your computer and use it in GitHub Desktop.
Small sluggifier static function. Simply call Slugifier::slugify($string)
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 | |
class Slugifier | |
{ | |
public static function slugify($string) | |
{ | |
$aArray = array('à', 'â', 'ä'); | |
$eArray = array('é', 'è', 'ê', 'ë'); | |
$iArray = array('î', 'ï'); | |
$oArray = array('ô', 'ö'); | |
$uArray = array('ù'); | |
$string = trim($string); | |
$string = strtolower($string); | |
$string = str_replace($aArray, 'a', $string); | |
$string = str_replace($eArray, 'e', $string); | |
$string = str_replace($iArray, 'i', $string); | |
$string = str_replace($oArray, 'o', $string); | |
$string = str_replace($uArray, 'u', $string); | |
$string = preg_replace('/\W+/', '-', $string); | |
return $string; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment