PHP Articles

Page 73 of 81

FILTER_CALLBACK constant in PHP

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

The FILTER_CALLBACK constant calls a user−defined function to filter the value. This constant is used with filter_var() to apply custom filtering logic by passing a callback function. Syntax filter_var($value, FILTER_CALLBACK, array("options" => "callback_function")); Parameters The callback function is specified in the options array and receives the input value as a parameter. The function should return the filtered value. Example 1: Using Built−in Function This example converts a string to lowercase using PHP's built−in strtolower() function ? demo text! Example 2: Using Custom Function ...

Read More

FILTER_SANITIZE_URL constant in PHP

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

The FILTER_SANITIZE_URL constant removes all illegal URL characters from a string, keeping only characters that are valid in URLs. This filter is useful for cleaning user input before using it in URL contexts. Allowed Characters The FILTER_SANITIZE_URL filter allows the following characters − $-_.+!*'(), {}|\^~[]`"> Original: https://example.com/search?q=hello world&type=web Sanitized: https://example.com/search?q=helloworld&type=web Key Points Spaces are removed from the input string Non-ASCII characters are stripped out Valid URL characters like ://, ?, &, and = are preserved This filter does not validate URLs, only sanitizes them Conclusion The ...

Read More

FILTER_SANITIZE_STRING constant in PHP

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

The FILTER_SANITIZE_STRING constant removes HTML tags and encodes special characters from a string. This filter is useful for cleaning user input to prevent XSS attacks. Note: As of PHP 8.1.0, FILTER_SANITIZE_STRING is deprecated. Use htmlspecialchars() or custom validation instead. Syntax filter_var($value, FILTER_SANITIZE_STRING, $flags) Flags FILTER_FLAG_NO_ENCODE_QUOTES − Do not encode quotes FILTER_FLAG_STRIP_LOW − Removes characters with ASCII value less than 32 FILTER_FLAG_STRIP_HIGH − Removes characters with ASCII value greater than 127 FILTER_FLAG_ENCODE_LOW − Encodes characters with ASCII value less than 32 FILTER_FLAG_ENCODE_HIGH − Encodes characters with ASCII value greater than 127 FILTER_FLAG_ENCODE_AMP − ...

Read More

FILTER_SANITIZE_SPECIAL_CHARS constant in PHP

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

The FILTER_SANITIZE_SPECIAL_CHARS constant filter HTML-escapes special characters like , &, and quotes to prevent XSS attacks and ensure safe display in HTML. Syntax filter_var($value, FILTER_SANITIZE_SPECIAL_CHARS, $flags) Flags FILTER_FLAG_STRIP_LOW − Strip characters with ASCII value below 32 FILTER_FLAG_STRIP_HIGH − Strip characters with ASCII value above 127 FILTER_FLAG_ENCODE_HIGH − Encode characters with ASCII value above 127 Return Value Returns the sanitized string with special characters HTML-encoded, or FALSE on failure. Example Here's how to sanitize a string containing HTML special characters ?

Read More

FILTER_SANITIZE_NUMBER_INT constant in PHP

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

The FILTER_SANITIZE_NUMBER_INT constant removes all characters except digits, plus and minus signs from a string. It's commonly used to clean user input before processing numeric data. Syntax filter_var($value, FILTER_SANITIZE_NUMBER_INT) Parameters The filter_var() function with FILTER_SANITIZE_NUMBER_INT accepts − $value − The string to be sanitized FILTER_SANITIZE_NUMBER_INT − The filter constant that removes illegal characters Return Value Returns a string containing only digits (0-9), plus (+), and minus (-) signs. All other characters are removed. Example Here's how to sanitize a string containing mixed characters ?

Read More

FILTER_SANITIZE_NUMBER_FLOAT constant in PHP

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

The FILTER_SANITIZE_NUMBER_FLOAT constant removes all illegal characters from a float number, keeping only digits, plus/minus signs, and optionally decimal points, thousand separators, or scientific notation based on the flags used. Syntax filter_var($value, FILTER_SANITIZE_NUMBER_FLOAT, $flags) Flags FILTER_FLAG_ALLOW_FRACTION − Allows decimal point (.) for fractions FILTER_FLAG_ALLOW_THOUSAND − Allows comma (, ) as thousand separator FILTER_FLAG_ALLOW_SCIENTIFIC − Allows e/E for scientific notation Return Value Returns the sanitized string with only valid float characters, or FALSE on failure. Example 1: Using ...

Read More

FILTER_SANITIZE_ENCODED constant in PHP

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

The FILTER_SANITIZE_ENCODED constant in PHP is used with the filter_var() function to URL-encode special characters in a string. This is particularly useful for sanitizing URLs and ensuring they contain only valid characters. Syntax filter_var($value, FILTER_SANITIZE_ENCODED, $flags) Flags and Options FILTER_FLAG_STRIP_LOW − Remove characters with ASCII value less than 32 FILTER_FLAG_STRIP_HIGH − Remove characters with ASCII value greater than 127 FILTER_FLAG_ENCODE_LOW − Encode characters with ASCII value less than 32 FILTER_FLAG_ENCODE_HIGH − Encode characters with ASCII value greater ...

Read More

FILTER_SANITIZE_EMAIL constant in PHP

Arjun Thakur
Arjun Thakur
Updated on 15-Mar-2026 475 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 547 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
Showing 721–730 of 802 articles
« Prev 1 71 72 73 74 75 81 Next »
Advertisements