Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # PHP slugify
- function slugify( $text, $unique_id = null ) {
- $old_locale = setlocale( LC_CTYPE, 0 );
- if( $old_locale != "en_US.UTF-8" ) {
- setlocale( LC_CTYPE, "en_US.UTF-8" );
- $old_locale = null;
- }
- $text = preg_replace('~[^\\pL\d]+~u', '-', $text);
- $text = trim($text, '-');
- if (function_exists('iconv')) { $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text); }
- $text = strtolower($text);
- $text = preg_replace('~[^-\w]+~', '', $text);
- if( $unique_id !== null ) {
- $text .= "-".$unique_id;
- }
- if( $old_locale !== null ) {
- setlocale( LC_CTYPE, $old_locale );
- }
- return $text;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement