2008
12.08
12.08
一些實用的 filter functions ,某些地方可以取代 regex 驗證
- filter_has_var — Checks if variable of specified type exists
- filter_id — Returns the filter ID belonging to a named filter
- filter_input_array — Gets external variables and optionally filters them
- filter_input — Gets a specific external variable by name and optionally filters it
- filter_list — Returns a list of all supported filters
- filter_var_array — Gets multiple variables and optionally filters them
- filter_var — Filters a variable with a specified filter
/* for an example: */
var_dump(filter_var('http://example.com', FILTER_VALIDATE_URL));
var_dump(filter_var('example@example.com', FILTER_VALIDATE_EMAIL));
var_dump(filter_var('example.com', FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED));
今天才知道這個東西,以後如果有機會要驗證表單的話,很多常用的欄位都不需自己再寫 regex 了(詳見官方文件)。

No Comment.
Add Your Comment