Return to Snippet

Revision: 17100
at January 12, 2010 22:13 by rombob


Updated Code
function stringUrlFormat($str){
	$underscore = chr(95);
	$space = chr(32);
	// compress multiple spaces
	$count = 1;
	while($count){
		$str = str_replace('  ', $space, $str, $count);
	}
	
	$str = str_replace($space, $underscore, $str);
	return $str;
}

Revision: 17099
at January 12, 2010 22:11 by rombob


Updated Code
function stringUrlFormat($str){
	$underscore = chr(95);
	$space = chr(32);
	// compress multiple spaces
	$count = 1;
	while($count){
		$str = str_replace('  ', ' ', $str, $count);
	}
	
	$str = str_replace($space, $underscore, $str);
	return $str;
}

Revision: 17098
at August 23, 2009 15:41 by rombob


Initial Code
function stringUrlEncode($str){
	$underscore=chr(95);
	$space=" ";
	// check and remove multiple spaces
	$strArr=array();
	$strTmp="";
	$str=trim($str);
	$strArr=explode($space, $str);
	for ($i = 0 ; $i < count($strArr) ; $i++) {
		if(empty($strArr[$i])){
			continue;
		}
		$word=trim($strArr[$i]);
		if(empty($strTmp)){
			$strTmp.=$word;
		} else {
			$strTmp.=$space.$word;
		}
	}
	$str=$strTmp;
	$strTmp=str_replace($space, $underscore, $strTmp);
	return $strTmp;
}

Initial URL


Initial Description
remove multiple spaces and replace with underscore

Initial Title
string to url compatible

Initial Tags
url

Initial Language
PHP