Home | PHP MySQL Hosting | PHP Host Blog | Yahoo Coupons |
PHP Hosting Articles
» PHP Hosting Coupons
» PHP Tutorials
» PHP Web Hosting
» PHP Resources
PHP Filters

PHP Filters- New to PHP? Wonder about the functionality referred to as PHP filters and filter functions? This article provides an introduction to PHP filters and filter functions. Read this PHP filter review to have a better understanding of PHP filters.

PHP Intro

PHP is a recursive acronym for PHP: Hypertext Preprocessor. It is a scripting language that can be used for server-side scripting, writing desktop applications, and command-line scripting, but is mainly used for creating dynamic web pages through embedding in HTML. The version in use as of July 2010 is PHP 5.3.3.

When PHP is used in interactive settings, such as web pages that include forms, for example, it needs a way to validate user input. To deal with this frequently occurring situation, as well as other data that is not secure, the filter functions of PHP provide checks on the input.

PHP Filter Functions

Seven PHP filter functions were introduced in PHP version 5. The filters perform several different functions:

• filter_has_var() yields true/false on whether a particular type of input exists, for example, a cookie.

• filter_id() returns a number or 'NULL' to specify the ID number that designates a particular filter.

• filter_input() gets and filters input that is outside the script.

• filter_input_array() gets and filters multiple inputs from outside the script.

• filter_list() returns an array including the names of all filters that are supported.

• filter_var() gets and filters a single variable.

• filter_var_array() gets and filters multiple variables.

PHP Filters

There are 18 PHP filters that call a filter function, sanitize input in various ways, and validate values. They can be used with various options and flags

—Calling a filter function

• FILTER_CALLBACK calls a filtering function that is user-defined and sets it to filtering data.

—Sanitizing input

• FILTER_SANITIZE_STRING strips tags that could be problematic to processing and deals with special characters, if desired

• FILTER_SANITIZE_STRIPPED is another name for the string filter

• FILTER_SANITIZE_ENCODED sanitizes characters that appear in URLs, such as the colon and slashes in http://

• FILTER_SANITIZE_SPECIAL_CHARS escapes specific characters, including single and double quotes, greater and less than signs, ampersands, and the ASCII decimal characters with a value of less than 32

• FILTER_SANITIZE_EMAIL removes all characters illegal in email, i.e., those that are not abcdefghijklmnopqrstuvwxyz (uppercase and lowercase), 0123456789, and !#$%&'*+-/=?^_`{|}~@.[]

• FILTER_SANITIZE_URL removes all characters illegal in a URL, i.e., those that are not abcdefghijklmnopqrstuvwxyz (uppercase and lowercase), 0123456789, and $-_.+!*'(),{}|^~[]`<>#%";/?:@&=

• FILTER_SANITIZE_NUMBER_INT removes all characters illegal in a number, i.e., those that are not 0123456789 and . +-

• FILTER_SANITIZE_NUMBER_FLOAT removes all characters illegal in a floating number, i.e., those that are not 0123456789 and +- and, optionally, .,eE

• FILTER_SANITIZE_MAGIC_QUOTES adds backslashes in front of single and double quotes, backslash, and NULL.

• FILTER_UNSAFE_RAW either does nothing or strips or encodes characters, depending on the flags.

—Validating Input

• FILTER_VALIDATE_INT validates a value either as an integer or as an integer within a specified range.

• FILTER_VALIDATE_BOOLEAN validates a Boolean option, returning TRUE for 1, true, on, and yes ; FALSE for 0, false, off, and no; and otherwise, NULL

• FILTER_VALIDATE_FLOAT validates the given value as a float number

• FILTER_VALIDATE_REGEXP validates against a regexp—a regular expression that is Perl-compatible.

• FILTER_VALIDATE_URL validates a value as a URL, which may e required to be RFC-compliant, include a host name, have a path after the second-level domain (the domain name), or include a query string.

• FILTER_VALIDATE_EMAIL validates a value as an email address, checking, for example, for spaces or other non-standard formatting.

• FILTER_VALIDATE_IP validates a value as an IP address, optionally specifying the format, an RFC-specified private range, or a value not within the reserved IP range.

Related Article: PHP vs ASP >>

Best PHP Hosts
  • $3.50/month!!!
  • Unlimited Space
  • Free SETUP
  • Unlimited Traffic
  • No Hidden FEES!
  • Unlimited Sites

  • VISIT TODAY ]
  • $4.45/month
  • Unlimited Traffic
  • Unlimited Space
  • Free PHP Scripts
  • Unlimited Websites
  • Email/FTP/MySQL

  • VISIT TODAY ]
  • $3.95/month
  • Unlimited Space
  • Unlimited Traffic
  • Free Domain Name
  • PHP Scripts/Tools
  • Unlimited Websites

  • VISIT TODAY ]

Copyright© 2009 - Best PHP Web Hosting Privacy Policy | About Us |