V2:Other Useful Methods
From PhpInputValidator
Contents |
addSlashes
Will add slashes to data. Will use custom add_slashes_function if set.
Params
$data
Data to add slashes to.
Return
Data with slashes.
Example
var_dump($getvar->addSlashes($test));
string(14) "It\'s my test!"
changeType
Type cast from one type to another.
Params
$value
Value to change.
$type
Type to typecast it to
Return
Data typecasted
Example
var_dump($getvar->changeType($test, 'int'));
int(123)
checkBetween
Check to ensure a value is:
Greater than or equal to the min
Less than or equal to the max
Only one of these two values are required
Params
$value
Value to check against.
$min
Minimum value
$max
Maximum value
Return
True/False
Example
var_dump($getvar->checkBetween($test, 1, 6));
bool(true)
checkLen
Check to ensure a string length is:
Greater than or equal to the min
Less than or equal to the max
Only one of these two values are required
Params
$string
String to check against.
$min
Minimum string length
$max
Maximum string length
Return
True/False
Example
var_dump($getvar->checkLen($test, 1, 3));
bool(false)
convertBRtoN
Changes br tages to \n
Params
$data
string to convert
Return
string
Example
var_dump($getvar->convertBRtoN($test));
string(20) "String
string
string"
convertNtoBR
Changes \n to br tages
Params
$data
string to convert
Return
string
Example
var_dump($getvar->convertNtoBR($test));
string(30) "String<br />string<br />string"
fixDBString
Fixes a string from a DB by removing slashes and fixing newlines
Params
$string
String to fix
Return
Fixed string
Example
var_dump($getvar->fixDBString($test));
string(28) "Line 1
Line 2
Line 3
Test's"
fixNewLines
Fixes newlines
Params
$string
String to fix
Return
Fixed string
Example
var_dump($getvar->fixNewLines($test));
string(26) "Line 1
Line 2
Line 3
Test"
Note
This function completely removes windows newlines:
\r
getInstance
Get's the current instance
Params
None
Return
Current Instance
getReason
Returns the reason the get() method failed
Return
string
Example
$test = $getvar->get('test', 'GET', 'int');
if ($getvar->isValid()) {
var_dump($getvar->getReason());
}
string(4) "type"
is
Is a value of that type
Params
$type
Type to test for
$value
Value to test
Return
True/False
Example
var_dump($getvar->is('int', $test));
bool(true)
is_set
Checks to see if a value isset and !empty in a location
Params
$name
Variable name
$location
Variable location
Return
True/False
Example
var_dump($getvar->is_set('test', 'GET'));
bool(true)
purify
Uses HTMLPurifier to purify HTML
Params
$data
Data to purify
Return
Purified string
Example
var_dump($getvar->purify($test));
string(18) "<b>Test<b></b></b>"
Note
If HTMLPurifer is not installed and not configured with phpInputValidator you will receive an error
stripHTML
Attempts to completely remove HTML from a string
Params
$data
Data to strip HTML From
Return
Clean string
Example
var_dump($getvar->stripHTML($test));
string(4) "Test"
stripSlahes
Strips slashes from a string
Params
$data
Data to strip slashes
Return
Clean string
Example
var_dump($getvar->stripSlahes($test));
string(13) "It's my test!"