All pastes #95837 Raw Edit

Miscellany

public text v1 · immutable
#95837 ·published 2006-07-22 10:52 UTC
rendered paste body
/**
 * Return a variable if it exists or $or if it doesn't.  Optionally require
 * variable to match specific syntax.
 * 
 * @param $var The variable to use.
 * @param $or The fallback.
 * @param $regex Optional, the regular expression to require of the var.
 * @return The variable's value.
 */
function ifsetor(&$var, $or, $regex = false) {
	if (empty($var) || ($regex && !preg_match($regex, $var))) {
		$var = $or;
	}
	
	return $var;
}