Slugify

/** * Converts human-readable strings into more machine-friendly formats * * @param string $text String to be formatted * @param string $separator The character that fills in spaces * * @return string $text Formatted text */ public function slugify( $text, $separator = '-' ) { $text = preg_replace( '~[^\\pL\d]+~u', $separator, $text ); $text = trim( $text, $separator ); $text = iconv( 'utf-8', 'us-ascii//TRANSLIT', $text ); $text = strtolower( $text ); $text = preg_replace( '~[^-\w]+~', '', $text ); if ( empty( $text ) ) { return 'n-a'; } return $text; }
Converts text strings to URL friendly, machine-friendly format. Adds hyphens, replaces some characters and converts to all lowercase.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.