Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Create a slug to use in a url
- * Dependency: php_intl (extension)
- *
- * @author Neophitus
- * @param string $text Text to transform
- * @param bool $tolower Convert or not to lowercase
- * @return string
- */
- function slug($text, $tolower = true)
- {
- $allowed = '~[^-,;.a-z0-9\s]~iu';
- $text = transliterator_transliterate('Any-Latin; Latin-ASCII', $text);
- if ($tolower) {
- $text = mb_strtolower($text);
- }
- $text = preg_replace($allowed, '', $text);
- $text = preg_replace('~[.,;)(\s]+~', '-', trim($text));
- $text = preg_replace('~-{2,}~', '-', $text);
- return $text;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement