note 111639 deleted from function.filter-input by aharvey
| From: | aharvey@php.net | Date: | Mon, 11 Mar 2013 16:21:16 +0000 |
| Subject: | note 111639 deleted from function.filter-input by aharvey | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-194034@lists.php.net to get a copy of this message | ||
Note Submitter: magictallguy at hotmail dot com
----
For those that aren't aware, you can use filter_input() in a one-line if() statement:
<?php
$_GET['ID'] = filter_input(INPUT_GET, 'ID', FILTER_SANITIZE_NUMBER_INT) ?: null;
echo $_GET['ID'];
?>
Assume that $_GET['ID'] = 1 - the code above would return 1
Whereas is we assume $_GET['ID'] = 1.56&someString - the code above would return null.
For those wanting just a completely clean INT, wrap $_GET['ID'] in abs() and intval()
<?php
$_GET['ID'] = filter_input(INPUT_GET, 'ID', FILTER_SANITIZE_NUMBER_INT) ?
abs(@intval($_GET['ID'])) : null;