Skip to content

Instantly share code, notes, and snippets.

@Tiriel
Created November 9, 2016 15:13
Show Gist options
  • Save Tiriel/3eb6ba728312b294c050de1efa439ba3 to your computer and use it in GitHub Desktop.
Save Tiriel/3eb6ba728312b294c050de1efa439ba3 to your computer and use it in GitHub Desktop.
Small sluggifier static function. Simply call Slugifier::slugify($string)
<?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