11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

www.it-ebooks.infoCHAPTER 13• WORKING WITH HTML FORMSTarget DataFloating-point numbersIntegersIP addressesRegular ExpressionsURLsIdentifierFILTER_VALIDATE_FLOATFILTER_VALIDATE_INTFILTER_VALIDATE_IPFILTER_VALIDATE_REGEXPFILTER_VALIDATE_URLYou can further tweak the behavior of these seven validation filters by passing flags into thefilter_var() function. For instance, you can request that solely IPV4 or IPV6 IP addresses are providedby passing in the FILTER_FLAG_IPV4 or FILTER_FLAG_IPV6 flags, respectively:$ipAddress = "192.168.1.01";if (filter_var($ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)){echo "Please provide an IPV6 address!";}Consult the <strong>PHP</strong> documentation for a complete list of available flags.Sanitizing Data with the Filter ExtensionAs I mentioned, it’s also possible to use the Filter component to sanitize data, which can be useful whenprocessing user input intended to be posted in a forum or blog comments. For instance, to remove alltags from a string, you can use the FILTER_SANITIZE_STRING:$userInput = "Love the site. E-mail me at Spammer.";$sanitizedInput = filter_var($userInput, FILTER_SANITIZE_STRING);// $sanitizedInput = Love the site. E-mail me at Spammer.A total of nine sanitization filters are currently supported, summarized in Table 13-2.Table 13-2. The Filter Extension’s Sanitization CapabilitiesIdentifierFILTER_SANITIZE_EMAILFILTER_SANITIZE_ENCODEDPurposeRemoves all characters from a string except those allowable within ane-mail address as defined within RFC 822(www.w3.org/Protocols/rfc822/).URL encodes a string, producing output identical to that returned bythe urlencode() function.295

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!