Encode
MaplePHP Encode Library
This PHP library, named MaplePHP\DTO\Format\Encode, provides functionality for encoding data, including JSON encoding, URL encoding, and special character encoding.
Encoding Configuration Methods
urlEncode(bool $encode): self
Sets the URL encoding flag.
Parameters:
$encode: Iftrue, URL encoding will be applied; otherwise, it will be skipped.
Returns:
An instance of the encoding object.
specialChar(bool $encode, int $flag = ENT_NOQUOTES): self
Sets the special character encoding flag.
Parameters:
$encode: Iftrue, special character encoding will be applied; otherwise, it will be skipped.$flag: The flag for special character encoding.
Returns:
An instance of the encoding object.
Encoding Methods
encode(?callable $callback = null): string|array
Encodes the value according to the specified encoding configurations.
Parameters:
$callback: Optional callback to access the encoded value and modify it further.
Returns:
The encoded value as a string or array.
urldecode(?callable $callback = null): string|array
Decodes the URL-encoded value.
Parameters:
$callback: Optional callback to access the decoded value and modify it further.
Returns:
The URL-decoded value as a string or array.
xss(?callable $callback = null): self
Applies special character encoding to protect against cross-site scripting (XXS).
Parameters:
$callback: Optional callback to access the encoded value and modify it further.
Returns:
An instance of the encoding object with special character encoding applied.
Properties
$jsonEncode: A boolean indicating whether JSON encoding is enabled.$specialChar: A boolean indicating whether special character encoding is enabled.$specialCharFlag: The flag for special character encoding.$urlencode: A boolean indicating whether URL encoding is enabled.
Last updated
Was this helpful?