@@ -117,6 +117,21 @@ IntVal( mixed $input ): int
117117```
118118Remove all characters except digits, plus and minus sign, and casts the value as an integer. Internally it uses [ filter_var] [ filter_var ] and ` (int) ` .
119119
120+ #### ` ip `
121+ ``` php
122+ Ip( string input, int filter = 0 ): int
123+ ```
124+ Sanitize the IP address or CIDR IP range. Internally it uses [ filter_var] [ filter_var ] . You can pass specific filters to sanitize your input:
125+
126+ ```
127+ FILTER_FLAG_IPV4
128+ FILTER_FLAG_IPV6
129+ FILTER_FLAG_NO_RES_RANGE
130+ FILTER_FLAG_NO_PRIV_RANGE
131+ ```
132+ By default, it will detect the IPv4 or IPv6 protocol if you do not use a predefined filter and sanitize the input.
133+ It will return ` false ` for invalid IP address or CIDR IP range.
134+
120135#### ` lower `
121136``` php
122137Lower( mixed $input ): string
@@ -220,6 +235,7 @@ const FILTER_BOOL = 'bool';
220235const FILTER_EMAIL = 'email';
221236const FILTER_FLOAT = 'float';
222237const FILTER_INT = 'int';
238+ const FILTER_IP = 'ip';
223239const FILTER_LOWER = 'lower';
224240const FILTER_LOWERFIRST = 'lowerfirst';
225241const FILTER_REGEX = 'regex';
@@ -262,6 +278,7 @@ $filter->bool(mixed $input): bool
262278$filter->email(string $input): string
263279$filter->float(mixed $input): float
264280$filter->int(string $input): int
281+ $filter->ip(string $input, int $filter = FILTER_FLAG_NONE): string|false
265282$filter->lower(string $input): string
266283$filter->lowerfirst(string $input): string
267284$filter->regex(mixed $input, mixed $pattern, mixed $replace): mixed
@@ -583,6 +600,7 @@ $filteredIp = $locator->sanitize('127.0.0.1', 'ipv4');
583600[ filter-sanitize-email ] : api/phalcon_filter.md#filtersanitizeemail
584601[ filter-sanitize-floatval ] : api/phalcon_filter.md#filtersanitizefloatval
585602[ filter-sanitize-intval ] : api/phalcon_filter.md#filtersanitizeintval
603+ [ filter-sanitize-ip ] : api/phalcon_filter.md#filtersanitizeip
586604[ filter-sanitize-lower ] : api/phalcon_filter.md#filtersanitizelower
587605[ filter-sanitize-lowerfirst ] : api/phalcon_filter.md#filtersanitizelowerfirst
588606[ filter-sanitize-regex ] : api/phalcon_filter.md#filtersanitizeregex
0 commit comments