filter_input กำหนดค่าและฟิวเตอร์ตัวแปรภายนอก เช่น $_GET,$_POST ใน PHP

16 ก.พ. 2017 , 4,342 Views   , หมวดหมู่ PHP ทุกหมวดหมู่ โค๊ดดิ้ง   ,


Parameters

type
One of INPUT_GET, INPUT_POST, INPUT_COOKIE, INPUT_SERVER, or INPUT_ENV.

variable_name
Name of a variable to get.

filter
The ID of the filter to apply. The Types of filters manual page lists the available filters.

If omitted, FILTER_DEFAULT will be used, which is equivalent to FILTER_UNSAFE_RAW. This will result in no filtering taking place by default.

options
Associative array of options or bitwise disjunction of flags. If filter accepts options, flags can be provided in “flags” field of array.


 

หากเราไม่ใช้ filter_input ในการกำหนดค่าตัวแปลภายนอก เราอาจจะต้องใช้โค๊ดด้านล่างนี้เพื่อไม่ให้ PHP แจ้งเออเลอร์ E_NOTICE, E_WARNING , E_ERROR.

เปลี่ยนจากโค๊ดด้านบนมาใช้โค๊ดด้านล่างในการกำหนดค่าตัวแปล

Yes, FILTER_REQUIRE_SCALAR seems to be set as a default option.
It’s very helpful for eliminating E_NOTICE, E_WARNING and E_ERROR.
This fact should be documented.

 

ดูเพิ่มเติม http://www.php.net/manual/en/function.filter-input.php