All pastes #824394 Raw Edit

Mine

public php v1 · immutable
·published 2007-12-19 22:59 UTC
rendered paste body
	/**	*	Clean	*	This will parse the supplied value as a hex value	*	*	@param		mixed	Value to be processed	*	@param		array	Parameters passed to the input handler	*	@return		mixed	hex string or number (if asNumeric is set)	*	@access 	public	*	@final	**/	public final static function clean( $value, Array $params )	{		$asNumeric = isset( $params['asNumeric'] ) && $params['asNumeric'];		$return = $asNumeric ? 0 : '0x0';			# Make sure is a string		if( !is_string( $value ) )			return $return;		# Remove 0x prefix if inserted		if( strpos( $value, '0x' ) === 0 )			$value = str_replace( '0x', '', $value );		if( !ctype_xdigit( $value ) )			return $return;		# Prep for compare		$numValue = hexdec( $value );		if( isset( $params['low'] ) && (float)$params['low'] > $numValue )		{			return $asNumeric ? (float)$params['low'] : (string)$params['low'];		}		elseif( isset( $params['high'] ) && (int)$params['high'] < $numValue )		{			return $asNumeric ? (float)$params['high'] : (string)$params['high'];		}		else			return $asNumeric ? $numValue : "0x$value";	}	/**	*	Validate	*	Checks the supplied value is a hexidecimal numeric string	*	and between bounds, if supplied	*	*	@param		mixed	Value to be processed	*	@param		array	Parameters passed to the input handler	*	@return		bool	*	@access 	public	*	@final	**/	public final static function validate( $value, Array $params )	{		return		(			is_string( $value ) && ctype_xdigit( $value )			&& ( !isset( $params['low'] ) || (float)$params['low'] < hexdec( $value ) )			&& ( !isset( $params['high'] ) || (float)$params['high'] > hexdec( $value ) )		);	}