.Maui Blog

Remove substring from string in PHP

/**
 * Remove substring from string
 *
 * Here is an inline example:
 * <code>
 * <?php
 * echo rmv('mxaxuxix', 'x'); // return 'maui'; * 
 * ?>
 * </code>
 * @param string $subject
 * @param mixed $remove[optional] <p>If omitted the function will remove whitespaces</p>
 * @return mixed
 */ 
function rmv($subject, $remove = " ") {
	$return = $subject;	
	
	if (!is_array($remove))
		$remove[0] = $remove;
	
	for ($i = 0; $i < count($remove); $i++)
		$return = str_replace($remove[$i], "", $return);
		
	return $return;
}
Exit mobile version