Return to Snippet

Revision: 70812
at July 16, 2016 14:37 by designfellow


Initial Code
function url_title($str, $separator = '-', $lowercase = FALSE)
	{
		if ($separator === 'dash')
		{
			$separator = '-';
		}
		elseif ($separator === 'underscore')
		{
			$separator = '_';
		}
		$q_separator = preg_quote($separator, '#');
		$trans = array(
			'&.+?;'			=> '',
			'[^\w\d _-]'		=> '',
			'\s+'			=> $separator,
			'('.$q_separator.')+'	=> $separator
		);
		$str = strip_tags($str);
		foreach ($trans as $key => $val)
		{
			$str = preg_replace('#'.$key.'#i'.(UTF8_ENABLED ? 'u' : ''), $val, $str);
		}
		if ($lowercase === TRUE)
		{
			$str = strtolower($str);
		}
		return trim(trim($str, $separator));
	}

Initial URL

                                

Initial Description
Convert space to dash

Initial Title
Convert space to dash

Initial Tags

                                

Initial Language
PHP