Str
in package
Table of Contents
- contains() : bool
- Polyfill for str_contains for PHP 7.4, using the native function if available.
- getExternalIP() : null|string
- Retrieves the system's current external IP address.
- hmac() : false|string
- Gets hash of given string.
- sanitize() : string
- Basic Sanitize and prepare for a string input for safe usage in the application.
- sanitizeHttpHost() : null|string
- Sanitizes the HTTP host.
- sanitizeKey() : mixed
- startsWith() : bool
- Polyfill for str_starts_with for PHP versions before 8.0, using the native function if available.
Methods
contains()
Polyfill for str_contains for PHP 7.4, using the native function if available.
public
static contains(string $haystack, string $needle) : bool
Parameters
- $haystack : string
-
The string to search in.
- $needle : string
-
The substring to search for.
Return values
bool —True if $haystack contains $needle, false otherwise.
getExternalIP()
Retrieves the system's current external IP address.
public
static getExternalIP([string $userAgent = 'Mozilla/5.0 (compatible; CustomBot/1.0)' ][, null|string $referrer = null ]) : null|string
This method attempts to fetch the external IP address of the system by sending a GET request to the "https://icanhazip.com/" service.
Parameters
- $userAgent : string = 'Mozilla/5.0 (compatible; CustomBot/1.0)'
-
Optional. The User-Agent string to use for the HTTP request. Defaults to 'Mozilla/5.0 (compatible; CustomBot/1.0)'.
- $referrer : null|string = null
-
Optional. The referrer URL to include in the HTTP request. Defaults to the value of the
HOME_URL
environment variable, if available.
Return values
null|string —The external IP address if successfully retrieved and valid, or null if the address could not be fetched or is invalid.
hmac()
Gets hash of given string.
public
static hmac(string $data, string $secretkey[, string $algo = 'sha256' ]) : false|string
Parameters
- $data : string
-
Message to be hashed.
- $secretkey : string
-
Secret key used for generating the HMAC variant.
- $algo : string = 'sha256'
-
Name of selected hashing algorithm (i.e. "md5", "sha256", "haval160,4", etc..)
Tags
Return values
false|string —Returns a string containing the calculated hash value.
sanitize()
Basic Sanitize and prepare for a string input for safe usage in the application.
public
static sanitize(string $input) : string
This function sanitizes the input by removing leading/trailing whitespace, stripping HTML and PHP tags, converting special characters to HTML entities, and removing potentially dangerous characters for security.
Parameters
- $input : string
-
The input string to sanitize.
Return values
string —The sanitized input ready for safe usage within the application.
sanitizeHttpHost()
Sanitizes the HTTP host.
public
sanitizeHttpHost(string $httpHost) : null|string
Parameters
- $httpHost : string
-
The HTTP host to sanitize.
Return values
null|string —The sanitized host or null if invalid.
sanitizeKey()
public
static sanitizeKey(string $key) : mixed
Parameters
- $key : string
Return values
mixed —startsWith()
Polyfill for str_starts_with for PHP versions before 8.0, using the native function if available.
public
static startsWith(string $haystack, string $needle) : bool
Parameters
- $haystack : string
-
The string to search in.
- $needle : string
-
The substring to search for.
Return values
bool —True if $haystack starts with $needle, false otherwise.