Raydium Framework

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.
passcode()  : string
Generates a one-time passcode (OTP) 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
see
https://www.php.net/manual/en/function.hash-hmac.php
Return values
false|string —

Returns a string containing the calculated hash value.

passcode()

Generates a one-time passcode (OTP) string.

public static passcode([int $length = 6 ][, string $type = 'numeric' ][, string $customChars = '' ]) : string
Parameters
$length : int = 6

Length of the generated OTP (default: 6)

$type : string = 'numeric'

Type of character set to use: 'numeric', 'alphanumeric', 'hex', 'custom', or a custom string.

$customChars : string = ''

(Optional) For a fully customized set of characters if $type is set to 'customString' (default empty).

Tags
throws
InvalidArgumentException

if $length is invalid or if $type/$customChars are misused.

Return values
string —

Generated OTP

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.

Search results