FILTER library PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
gautamz07
Forum Contributor
Posts: 331
Joined: Wed May 14, 2014 12:18 pm

FILTER library PHP

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: FILTER library PHP

Post 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.
User avatar
gautamz07
Forum Contributor
Posts: 331
Joined: Wed May 14, 2014 12:18 pm

Re: FILTER library PHP

Post by gautamz07 »

Thanks !
Post Reply