دالة PHP filter_input_array()
التعريف والاستخدام
يستخدم دالة filter_input_array() للحصول على عدة إدخالات من خارج السكربت، ثم تقوم بتحليلها.
لا تحتاج هذه الوظيفة إلى استدعاء filter_input() مرة أخرى، مما يكون مفيدًا جدًا لتحليل متغيرات الإدخال المتعددة.
يمكن لهذه الوظيفة الحصول على إدخال من مصادر متعددة:
- INPUT_GET
- INPUT_POST
- INPUT_COOKIE
- INPUT_ENV
- INPUT_SERVER
- INPUT_SESSION (لم يتم تنفيذه بعد)
- INPUT_REQUEST (لم يتم تنفيذه بعد)
إذا كانت النتيجة ناجحة، يتم إرجاع البيانات الم过滤ة، وإذا كانت الفشل يتم إرجاع false.
النحو
filter_input(input_type, args)
المتغير | الوصف |
---|---|
input_type | ضروري. تحديد نوع الإدخال. انظر القائمة أعلاه للأنواع الممكنة. |
args |
Optional. Specifies an array of filter parameters. Valid array keys are variable names. Valid values are filter IDs, or arrays specifying filters, flags, and options. The parameter can also be a single filter ID. If so, all values in the input array are filtered by the specified filter. |
Tips and Comments
Tip:See alsoComplete PHP Filter Reference Manual, see the filters that can be used with this function.
Example
In this example, we use the filter_input_array() function to filter three POST variables. The accepted POST variables are name, age, and email address:
<?php $filters = array ( "name" => array ( "filter"=>FILTER_CALLBACK, "flags"=>FILTER_FORCE_ARRAY, "options"=>"ucwords" ), "age" => array ( "filter"=>FILTER_VALIDATE_INT, "options"=>array ( "min_range"=>1, "max_range"=>120 ) ), "email"=> FILTER_VALIDATE_EMAIL, ); print_r(filter_input_array(INPUT_POST, $filters)); ?>
Output similar to:
Array ( [name] => Peter [age] => 41 [email] => peter@example.com )