js实现类似php的explode功能

调用方法和返回值和php一样

function explode(separators,inputstring,includeEmpties) {
	inputstring = new String(inputstring);
	separators = new String(separators);

	if(separators == "undefined") {
		separators = " :;";
	}
	fixedExplode = new Array(1);
	currentElement = "";
	count = 0;

	for(x=0; x < inputstring.length; x++) {
		str = inputstring.charAt(x);
		if(separators.indexOf(str) != -1) {
			if ( ( (includeEmpties <= 0) || (includeEmpties == false)) && (currentElement == "")) {
				
			}else{
				fixedExplode[count] = currentElement;
				count++;
				currentElement = "";
			}
		}else{
			currentElement += str;
		}
	}

	if (( ! (includeEmpties <= 0) && (includeEmpties != false)) || (currentElement != "")) {
		fixedExplode[count] = currentElement;
	}
	return fixedExplode;
}
鄂ICP备19018033号-1
0.062262s