WooCommerce Code Reference

StringUtil
in package

A class of utilities for dealing with strings.

Table of Contents

class_name_without_namespace()  : string
Get the name of a class without the namespace.
contains()  : bool
Checks if one string is contained into another at any position.
ends_with()  : bool
Checks to see whether or not a string ends with another.
is_null_or_empty()  : bool
Check if a string is null or is empty.
is_null_or_whitespace()  : bool
Check if a string is null, is empty, or has only whitespace characters (space, tab, vertical tab, form feed, carriage return, new line)
normalize_local_path_slashes()  : string|null
Normalize the slashes (/ and \) of a local filesystem path by converting them to DIRECTORY_SEPARATOR.
plugin_name_from_plugin_file()  : string
Get the name of a plugin in the form 'directory/file.php', as in the keys of the array returned by 'get_plugins'.
starts_with()  : bool
Checks to see whether or not a string starts with another.
to_sql_list()  : string
Convert an array of values to a list suitable for a SQL "IN" statement (so comma separated and delimited by parenthesis).

Methods

class_name_without_namespace()

Get the name of a class without the namespace.

public static class_name_without_namespace(string $class_name) : string
Parameters
$class_name : string

The full class name.

Return values
stringThe class name without the namespace.

contains()

Checks if one string is contained into another at any position.

public static contains(string $string, string $contained[, bool $case_sensitive = true ]) : bool
Parameters
$string : string

The string we want to check.

$contained : string

The string we're looking for inside $string.

$case_sensitive : bool = true

Indicates whether the comparison should be case-sensitive.

Return values
boolTrue if $contained is contained inside $string, false otherwise.

ends_with()

Checks to see whether or not a string ends with another.

public static ends_with(string $string, string $ends_with[, bool $case_sensitive = true ]) : bool
Parameters
$string : string

The string we want to check.

$ends_with : string

The string we're looking for at the end of $string.

$case_sensitive : bool = true

Indicates whether the comparison should be case-sensitive.

Return values
boolTrue if the $string ends with $ends_with, false otherwise.

is_null_or_empty()

Check if a string is null or is empty.

public static is_null_or_empty(string|null $value) : bool
Parameters
$value : string|null

The string to check.

Return values
boolTrue if the string is null or is empty.

is_null_or_whitespace()

Check if a string is null, is empty, or has only whitespace characters (space, tab, vertical tab, form feed, carriage return, new line)

public static is_null_or_whitespace(string|null $value) : bool
Parameters
$value : string|null

The string to check.

Return values
boolTrue if the string is null, is empty, or contains only whitespace characters.

normalize_local_path_slashes()

Normalize the slashes (/ and \) of a local filesystem path by converting them to DIRECTORY_SEPARATOR.

public static normalize_local_path_slashes(string|null $path) : string|null
Parameters
$path : string|null

Path to normalize.

Return values
string|nullNormalized path, or null if the input was null.

plugin_name_from_plugin_file()

Get the name of a plugin in the form 'directory/file.php', as in the keys of the array returned by 'get_plugins'.

public static plugin_name_from_plugin_file(string $plugin_file_path) : string
Parameters
$plugin_file_path : string

The path of the main plugin file (can be passed as FILE from the plugin itself).

Return values
stringThe name of the plugin in the form 'directory/file.php'.

starts_with()

Checks to see whether or not a string starts with another.

public static starts_with(string $string, string $starts_with[, bool $case_sensitive = true ]) : bool
Parameters
$string : string

The string we want to check.

$starts_with : string

The string we're looking for at the start of $string.

$case_sensitive : bool = true

Indicates whether the comparison should be case-sensitive.

Return values
boolTrue if the $string starts with $starts_with, false otherwise.

to_sql_list()

Convert an array of values to a list suitable for a SQL "IN" statement (so comma separated and delimited by parenthesis).

public static to_sql_list(array<string|int, mixed> $values) : string

e.g.: [1,2,3] --> (1,2,3)

Parameters
$values : array<string|int, mixed>

The values to convert.

Tags
throws
InvalidArgumentException

Empty values array passed.

Return values
stringA parenthesized and comma-separated string generated from the values.