Return to Snippet

Revision: 8716
at October 4, 2008 12:11 by evanwalsh


Updated Code
<?php
/*
	Function: eexplode
	
	Explodes an string and removes any empty 
	elements in the resulting array
	
	Parameters: 
		$separator - The separator used to explode the $string
		$string - The string to explode
		
	Returns:
		An array with no empty elements
		
	Example:
		print_r(explode(":","evan:walsh:"));

		Array(
			[0] => evan
			[1] => walsh
			[2] => 
		);

		print_r(eexplode(":","evan:walsh:"));

		Array(
			[0] => evan
			[1] => walsh
		);
 */
function eexplode($separator,$string){
	$array = explode($separator,$string);
	foreach($array as $key => $val){
		if(empty($val)){
			unset($array[$key]);
		}
	}
	return $array;
}

Revision: 8715
at October 4, 2008 12:09 by evanwalsh


Initial Code
<?php
/*
	Function: eexplode
	
	Explodes an string and removes any empty 
	elements in the resulting array
	
	Parameters: 
		$separator - The separator used to explode the $string
		$string - The string to explode
		
	Returns:
		An array with no empty elements
 */
function eexplode($separator,$string){
	$array = explode($separator,$string);
	foreach($array as $key => $val){
		if(empty($val)){
			unset($array[$key]);
		}
	}
	return $array;
}

/*
	Example:
		print_r(explode(":","evan:walsh:"));
		
		Array(
			[0] => evan
			[1] => walsh
			[2] => 
		);
		
		print_r(eexplode(":","evan:walsh:"));
		
		Array(
			[0] => evan
			[1] => walsh
		);
*/

Initial URL
http://nothingconcept.com

Initial Description

                                

Initial Title
Explode a string and return an array with no empty elements

Initial Tags
array

Initial Language
PHP