InputItem
in package
Input Object
Represents an input item from various sources such as GET, POST, SESSION, or COOKIE.
Tags
Table of Contents
- $type : string|null
- $value : mixed
- __construct() : mixed
- Class Constructor
- all() : mixed
- Get the raw input value.
- color() : string|array<string|int, mixed>
- Get the color value. Returns a string or an array of strings.
- create() : static
- Create an InputItem object.
- date() : string|array<string|int, mixed>|null
- Get the date and time value.
- description() : string
- Get the sanitized and truncated text.
- detail() : string
- Remove PHP tags and escape characters for text input from an editor.
- exists() : bool
- Check if the input variable exists.
- filter() : string|array<string|int, mixed>
- Filter the input value based on a regular expression pattern.
- isCookie() : bool
- Check if the input is from a COOKIE variable.
- isGet() : bool
- Check if the input is from a GET variable.
- isPost() : bool
- Check if the input is from a POST variable.
- isSession() : bool
- Check if the input is from a SESSION variable.
- keywords() : string
- Get the sanitized and truncated keywords from the input value.
- number() : string|array<string|int, mixed>
- Extracts numbers or an array of numbers from the input.
- password() : string|array<string|int, mixed>
- Validates and filters the input as a password.
- quote() : string|array<string|int, mixed>
- Accepts text input and converts single quotes to HTML entity ''', and trims leading and trailing spaces.
- text() : string|array<string|int, mixed>
- Accepts text input and converts special characters '&', '"', "'", '<', '>', and '\' to their corresponding HTML entities, and trims leading and trailing spaces.
- textarea() : string|array<string|int, mixed>
- Converts '<', '>', '\', '{', '}', and '\n' to their corresponding HTML entities, converts '\n' to '<br>', and trims leading and trailing spaces.
- time() : string|null
- Get the time value.
- toArray() : array<string|int, mixed>
- Converts the input value to an array.
- toBoolean() : bool|array<string|int, mixed>
- Converts the input value to a boolean or an array of booleans.
- toDouble() : float|array<string|int, mixed>
- Converts the input value to a double.
- toFloat() : float|array<string|int, mixed>
- Converts the input value to a float or an array of floats.
- toInt() : int|array<string|int, mixed>
- Converts the input value to an integer or an array of integers.
- toObject() : object|array<string|int, mixed>
- Converts the input value to an object or an array of objects.
- topic() : string|array<string|int, mixed>
- Converts tags and removes extra spaces (not exceeding 1 space) without line breaks.
- toString() : string|array<string|int, mixed>|null
- Converts the input value to a string, an array of strings, or null.
- url() : string|array<string|int, mixed>
- Converts tags without converting & and removes trailing spaces.
- username() : string|array<string|int, mixed>
- Accepts email addresses and phone numbers only.
- checkValue() : string
- Check the validity of a value.
- cut() : string
- Truncate a string to a specified length.
Properties
$type
protected
string|null
$type
The input type (e.g., GET, POST, SESSION, COOKIE)
$value
protected
mixed
$value
The input value
Methods
__construct()
Class Constructor
public
__construct([mixed $value = null ][, string|null $type = null ]) : mixed
Parameters
- $value : mixed = null
-
The input value (default: null)
- $type : string|null = null
-
The input type (e.g., GET, POST, SESSION, COOKIE) (default: null)
Return values
mixed —all()
Get the raw input value.
public
all() : mixed
Return values
mixed —The raw input value
color()
Get the color value. Returns a string or an array of strings.
public
color() : string|array<string|int, mixed>
Tags
Return values
string|array<string|int, mixed> —The color value
create()
Create an InputItem object.
public
static create(mixed $value[, string|null $type = null ]) : static
Parameters
- $value : mixed
-
The input value
- $type : string|null = null
-
The input type (e.g., GET, POST, SESSION, COOKIE) (default: null)
Return values
static —The created InputItem object
date()
Get the date and time value.
public
date([bool $strict = false ]) : string|array<string|int, mixed>|null
Returns null if the date value is empty or not in the correct format.
Parameters
- $strict : bool = false
-
True to validate the date value strictly, false to skip validation (default: false)
Tags
Return values
string|array<string|int, mixed>|null —The date and time value
description()
Get the sanitized and truncated text.
public
description(int $len) : string
Removes tags and unwanted characters from the text.
Parameters
- $len : int
-
The maximum length of the text (default: 0)
Tags
Return values
string —The sanitized and truncated text
detail()
Remove PHP tags and escape characters for text input from an editor.
public
detail() : string
Tags
Return values
string —The sanitized text
exists()
Check if the input variable exists.
public
exists() : bool
Return values
bool —True if the input variable exists, false otherwise
filter()
Filter the input value based on a regular expression pattern.
public
filter(string $format[, string $replace = '' ]) : string|array<string|int, mixed>
Parameters
- $format : string
-
The regular expression pattern to filter the input value
- $replace : string = ''
-
The replacement string for filtered characters (default: '')
Tags
Return values
string|array<string|int, mixed> —The filtered input value
isCookie()
Check if the input is from a COOKIE variable.
public
isCookie() : bool
Return values
bool —True if the input is from a COOKIE variable, false otherwise
isGet()
Check if the input is from a GET variable.
public
isGet() : bool
Return values
bool —True if the input is from a GET variable, false otherwise
isPost()
Check if the input is from a POST variable.
public
isPost() : bool
Return values
bool —True if the input is from a POST variable, false otherwise
isSession()
Check if the input is from a SESSION variable.
public
isSession() : bool
Return values
bool —True if the input is from a SESSION variable, false otherwise
keywords()
Get the sanitized and truncated keywords from the input value.
public
keywords(int $len) : string
Removes tags, whitespace, and unwanted characters from the input value.
Parameters
- $len : int
-
The maximum length of the keywords (default: 0)
Tags
Return values
string —The sanitized and truncated keywords
number()
Extracts numbers or an array of numbers from the input.
public
number() : string|array<string|int, mixed>
Tags
Return values
string|array<string|int, mixed> —The extracted numbers or an array of extracted numbers
password()
Validates and filters the input as a password.
public
password() : string|array<string|int, mixed>
This function is used to validate and filter the input as a password. It ensures that
the value consists of non-space characters only. The resulting value is filtered using
the Text::password() function.
Return values
string|array<string|int, mixed> —The validated and filtered password
quote()
Accepts text input and converts single quotes to HTML entity ''', and trims leading and trailing spaces.
public
quote() : string|array<string|int, mixed>
This function accepts text input and converts single quotes to the HTML entity '''. It also trims leading and trailing spaces from the input value.
Tags
Return values
string|array<string|int, mixed> —The processed text
text()
Accepts text input and converts special characters '&', '"', "'", '<', '>', and '\' to their corresponding HTML entities, and trims leading and trailing spaces.
public
text() : string|array<string|int, mixed>
This function accepts text input and converts the special characters '&', '"', "'", '<', '>', and '' to their corresponding HTML entities. It also trims leading and trailing spaces from the input value. This function is useful for sanitizing input that does not allow HTML tags.
Tags
Return values
string|array<string|int, mixed> —The processed text
textarea()
Converts '<', '>', '\', '{', '}', and '\n' to their corresponding HTML entities, converts '\n' to '<br>', and trims leading and trailing spaces.
public
textarea() : string|array<string|int, mixed>
Used for receiving data from a textarea input.
Tags
Return values
string|array<string|int, mixed> —The processed textarea input
time()
Get the time value.
public
time([bool $strict = false ]) : string|null
Returns null if the time value is empty or in the wrong format.
Parameters
- $strict : bool = false
-
True to validate the time value strictly, false to skip validation (default: false)
Tags
Return values
string|null —The time value
toArray()
Converts the input value to an array.
public
toArray() : array<string|int, mixed>
This function returns the input value as an array. If the value is not an array, an error is thrown.
Tags
Return values
array<string|int, mixed> —The converted array value
toBoolean()
Converts the input value to a boolean or an array of booleans.
public
toBoolean() : bool|array<string|int, mixed>
This function returns 1 if the input value is not empty, and 0 otherwise.
Tags
Return values
bool|array<string|int, mixed> —The converted boolean value
toDouble()
Converts the input value to a double.
public
toDouble() : float|array<string|int, mixed>
This function converts the input value to a double. If the value is null, it returns 0. The function removes any commas from the value before conversion.
Tags
Return values
float|array<string|int, mixed> —The converted double value
toFloat()
Converts the input value to a float or an array of floats.
public
toFloat() : float|array<string|int, mixed>
Tags
Return values
float|array<string|int, mixed> —The converted float value
toInt()
Converts the input value to an integer or an array of integers.
public
toInt() : int|array<string|int, mixed>
Tags
Return values
int|array<string|int, mixed> —The converted integer value
toObject()
Converts the input value to an object or an array of objects.
public
toObject() : object|array<string|int, mixed>
Tags
Return values
object|array<string|int, mixed> —The converted object value
topic()
Converts tags and removes extra spaces (not exceeding 1 space) without line breaks.
public
topic([bool $double_encode = true ]) : string|array<string|int, mixed>
Used for article titles.
Parameters
- $double_encode : bool = true
-
true (default) to convert HTML entities like & to &, false otherwise
Tags
Return values
string|array<string|int, mixed> —The processed topic string
toString()
Converts the input value to a string, an array of strings, or null.
public
toString() : string|array<string|int, mixed>|null
Caution: This function converts the value to a string without any validation. Use with caution.
Tags
Return values
string|array<string|int, mixed>|null —The converted string value
url()
Converts tags without converting & and removes trailing spaces.
public
url() : string|array<string|int, mixed>
Used for URLs or emails.
Tags
Return values
string|array<string|int, mixed> —The processed URL string
username()
Accepts email addresses and phone numbers only.
public
username() : string|array<string|int, mixed>
Tags
Return values
string|array<string|int, mixed> —The processed username string
checkValue()
Check the validity of a value.
private
checkValue(string $value) : string
Validates the value against a regular expression pattern. If the value matches the pattern, an exception is thrown indicating an invalid value.
Parameters
- $value : string
-
The value to be checked
Tags
Return values
string —The validated value
cut()
Truncate a string to a specified length.
private
cut(string $str, int $len) : string
Truncates the given string to the specified length. If the length parameter
is provided and the string is not empty, the string will be shortened to the
specified length using mb_substr().
Parameters
- $str : string
-
The string to be truncated
- $len : int
-
The maximum length of the truncated string
Return values
string —The truncated string