Return to Snippet

Revision: 32473
at September 26, 2010 01:37 by nilambar


Initial Code
/*
*	getSlug()
*	@action:return cleaned text of given string
*			Used to get url friendly title
*	@parameters:
*		$str: string to be cleaned
*		$replace: array of characters to be cleaned; default empty
*		$delimiter: delimiter to separate words; default is '-'
*	@return: string of given length
*	@modified : 19 September 2010
*	@modified by: Nilambar
*/
function getSlug($str, $replace=array(), $delimiter='-') {
	setlocale(LC_ALL, 'en_US.UTF8');
	//
	if( !empty($replace) ) {
		$str = str_replace((array)$replace, ' ', $str);
	}
	$clean = iconv('UTF-8', 'ASCII//TRANSLIT', $str);	
	$clean=strip_tags($clean);
	$clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean);
	$clean = strtolower(trim($clean, '-'));
	$clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean);
	return $clean;
}

Initial URL

                                

Initial Description
Get url friendly string

Initial Title
Get slug(URL friendly string)

Initial Tags
php

Initial Language
PHP