Strings helpers

List of functions that works for PHP strings.

is_json

Since PHP 8.3+ this function will throw a deprecated warning message to move to PHP's native function instead (json_validate) which works similarly.

Check if a variable is a valid json string.

$json = '{}';

\OpenSoutheners\ExtendedPhp\Strings\is_json($json); // true

is_json_structure

Similarly than is_json function but this one also checks if the data inside the string is also a valid JSON data structure (starting with { or [):

$json = '1';

\OpenSoutheners\ExtendedPhp\Strings\is_json_structure($json); // false

get_email_domain

Get domain part from email address:

$email = 'hello@mydomain.com';

\OpenSoutheners\ExtendedPhp\Strings\get_email_domain($email); // 'mydomain.com'

Last updated