Page 1 of 1

FILTER library PHP

Posted: Mon Dec 15, 2014 11:42 pm
by gautamz07
given this below snippet of code :

Code: Select all

<?php

	$data = array('age' => 21, 
				'rating' => 4,
				'price' => 9.95,
				'thousands' => '100,000.95',
				'european' => '100.000,95'
				 );	
			$instructions = array('age' => FILTER_VALIDATE_INT,
								
								'rating' => array('filter' => FILTER_VALIDATE_INT,
									'options' => array('min_range' => 1,
									'max_range' => 5)),

								'price' => array('filter' => FILTER_SANITIZE_NUMBER_FLOAT,
									'flags' => FILTER_FLAG_ALLOW_FRACTION),

								'thousands' => array('filter' => FILTER_SANITIZE_NUMBER_FLOAT,
									'flags' => FILTER_FLAG_ALLOW_FRACTION |
									FILTER_FLAG_ALLOW_THOUSAND),

								'european' => array('filter' => FILTER_VALIDATE_FLOAT,
									'options' => array('decimal' => ','),
									'flags' => FILTER_FLAG_ALLOW_THOUSAND)
			);
	$filtered = filter_var_array($data, $instructions);

?>
how do i find out that weather any validator of a single feild has failed ??

also , for every key in $data is it necessary for a key with the same name and in the same order to be present in $instructions ?

Thank you.

gautam.

Re: FILTER library PHP

Posted: Tue Dec 16, 2014 12:50 am
by requinix
The documentation would be a great way to answer your questions.

Note that it does not say that the values in $instructions have to be in the same order.

Re: FILTER library PHP

Posted: Thu Dec 18, 2014 12:12 pm
by gautamz07
Thanks !