Server Side Programming Articles

Page 1061 of 2109

FILTER_SANITIZE_EMAIL constant in PHP

Arjun Thakur
Arjun Thakur
Updated on 15-Mar-2026 492 Views

The FILTER_SANITIZE_EMAIL constant removes all characters from a string that are not allowed in an email address according to RFC standards. This filter is useful for cleaning user input before validation or storage. Syntax filter_var($email, FILTER_SANITIZE_EMAIL) Parameters The filter_var() function accepts the following parameters when used with FILTER_SANITIZE_EMAIL − $email − The email string to be sanitized FILTER_SANITIZE_EMAIL − The filter constant that removes illegal email characters Return Value Returns the sanitized email string with illegal characters removed, or FALSE on failure. Example The following example demonstrates ...

Read More

FILTER_VALIDATE_URL constant in PHP

Ankith Reddy
Ankith Reddy
Updated on 15-Mar-2026 565 Views

The FILTER_VALIDATE_URL constant validates a URL and returns the validated URL on success or FALSE on failure. It's commonly used with the filter_var() function to check if a string contains a valid URL format. Syntax filter_var($url, FILTER_VALIDATE_URL, $flags) Parameters $url − The URL string to validate FILTER_VALIDATE_URL − The validation filter constant $flags − Optional flags to specify additional requirements Available Flags FILTER_FLAG_SCHEME_REQUIRED − URL must be RFC compliant with a scheme (http, https, etc.) FILTER_FLAG_HOST_REQUIRED − URL must include host name FILTER_FLAG_PATH_REQUIRED − URL must have a path ...

Read More

FILTER_VALIDATE_REGEXP constant in PHP

George John
George John
Updated on 15-Mar-2026 1K+ Views

The FILTER_VALIDATE_REGEXP constant validates a value against a Perl-compatible regular expression. It returns the validated value if the pattern matches, or FALSE on failure. Syntax filter_var($value, FILTER_VALIDATE_REGEXP, $options) Parameters $value − The string to validate $options − An array containing the "regexp" key with the pattern to match against Return Value Returns the validated string if it matches the pattern, or FALSE if validation fails. Example 1: Basic Pattern Matching This example validates an email domain pattern ? Matched String! ...

Read More

FILTER_VALIDATE_IP constant in PHP

Chandu yadav
Chandu yadav
Updated on 15-Mar-2026 880 Views

The FILTER_VALIDATE_IP constant validates an IP address using PHP's filter_var() function. It checks if a given string is a valid IPv4 or IPv6 address format. Syntax filter_var($value, FILTER_VALIDATE_IP, $flags) Parameters $value − The IP address string to validate FILTER_VALIDATE_IP − The validation filter constant $flags − Optional flags to specify validation criteria Flags FILTER_FLAG_IPV4 − The value must be a valid IPv4 address FILTER_FLAG_IPV6 − The value must be a valid IPv6 address FILTER_FLAG_NO_PRIV_RANGE − The value must not be within a private range FILTER_FLAG_NO_RES_RANGE − The value must ...

Read More

FILTER_VALIDATE_FLOAT constant in PHP

Ankith Reddy
Ankith Reddy
Updated on 15-Mar-2026 381 Views

The FILTER_VALIDATE_FLOAT constant validates whether a value is a valid float number. It returns the filtered data on success, or FALSE on failure. Syntax filter_var($value, FILTER_VALIDATE_FLOAT, $flags) Parameters $value − The value to validate as a float $flags (optional) − Additional flags like FILTER_FLAG_ALLOW_THOUSAND Return Value Returns the validated float value on success, or FALSE on failure. Example 1: Basic Float Validation float(291.9) Example 2: Testing Different Values Without flag: bool(false) With thousand separator flag: float(1234.56) ...

Read More

FILTER_VALIDATE_EMAIL constant in PHP

George John
George John
Updated on 15-Mar-2026 494 Views

The FILTER_VALIDATE_EMAIL constant is used with PHP's filter_var() function to validate email addresses. It checks if an email follows the standard email format and returns the email if valid, or false if invalid. Syntax filter_var($email, FILTER_VALIDATE_EMAIL) Return Value Returns the validated email address on success, or false on failure. Example Here's how to validate an email address using FILTER_VALIDATE_EMAIL − example@demo.com = valid email address Testing Invalid Emails Let's test with various invalid email formats − valid@example.com ...

Read More

FILTER_VALIDATE_BOOLEAN constant in PHP

Chandu yadav
Chandu yadav
Updated on 15-Mar-2026 446 Views

The FILTER_VALIDATE_BOOLEAN constant validates a value as a boolean option. It's useful when you need to convert string representations of boolean values into actual PHP boolean types. Return Value The FILTER_VALIDATE_BOOLEAN constant returns: TRUE for "1", "true", "on" and "yes" FALSE for "0", "false", "off" and "no" NULL for any other value Syntax filter_var($value, FILTER_VALIDATE_BOOLEAN, $flags) Example 1: Valid TRUE Values This example shows values that return TRUE − bool(true) bool(true) bool(true) Example 2: Valid FALSE Values This example demonstrates ...

Read More

filter_var() function in PHP

Ankith Reddy
Ankith Reddy
Updated on 15-Mar-2026 639 Views

The filter_var() function is used to filter a variable with a specified filter. It provides a convenient way to validate and sanitize data in PHP applications. Syntax filter_var(variable, filter, options) Parameters variable − The value to filter filter − The filter ID that specifies the filter to apply options − Optional flags or options for the filter Return Value The filter_var() function returns the filtered data on success, or FALSE on failure. Example 1: Email Validation This example demonstrates validating an email address using FILTER_VALIDATE_EMAIL ? ...

Read More

filter_list() function in PHP

Chandu yadav
Chandu yadav
Updated on 15-Mar-2026 507 Views

The filter_list() function in PHP returns an array of all available filter names that can be used with PHP's filter functions like filter_var() and filter_input(). Syntax filter_list() Parameters This function does not accept any parameters. Return Value The function returns an indexed array containing the names of all available filters. If no filters are available, it returns an empty array. Example Here's how to use filter_list() to display all available filters − Practical Example with Filter IDs You can combine filter_list() with filter_id() to ...

Read More

filter_input() function in PHP

Ankith Reddy
Ankith Reddy
Updated on 15-Mar-2026 714 Views

The filter_input() function gets an external variable by name and optionally filters it using built-in PHP filters. It's commonly used to sanitize and validate user input from forms, URLs, cookies, and server variables. Syntax filter_input(type, var, filtername, options) Parameters type − Specifies the input type. Five constants are available: INPUT_GET, INPUT_POST, INPUT_COOKIE, INPUT_SERVER, or INPUT_ENV. var − The name of the variable to filter. filtername − The ID of the filter to apply (e.g., FILTER_VALIDATE_EMAIL, FILTER_SANITIZE_STRING). options − Optional flags or options for the filter. Return Value Returns the filtered ...

Read More
Showing 10601–10610 of 21,090 articles
Advertisements