Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Programming Articles
Page 1074 of 2547
FILTER_SANITIZE_STRING constant in PHP
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 MoreFILTER_SANITIZE_SPECIAL_CHARS constant in PHP
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 MoreFILTER_SANITIZE_NUMBER_INT constant in PHP
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 MoreFILTER_SANITIZE_NUMBER_FLOAT constant in PHP
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 MoreFILTER_SANITIZE_ENCODED constant in PHP
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 MoreFILTER_SANITIZE_EMAIL constant in PHP
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 MoreFILTER_VALIDATE_URL constant in PHP
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 MoreFILTER_VALIDATE_REGEXP constant in PHP
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 MoreFILTER_VALIDATE_IP constant in PHP
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 MoreFILTER_VALIDATE_FLOAT constant in PHP
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