O3PO_Utility
in package
A collection of various utility functions.
Tags
Table of Contents
Properties
- $stop_words : array<string|int, mixed>
- Array of stopwords.
Methods
- array_mean() : int|float
- Compute the mean
- array_median() : float|int
- Compute the median.
- array_stddev() : float
- Compute the standard deviation
- base_convert_arbitrary_precision() : mixed
- Arbitrary precision base_convert().
- check_orcid() : mixed
- Check that the given ORCID is well formated.
- is_assoc() : bool
- Test whether an array is associative or enumerated.
- make_slash_breakable_html() : mixed
- Make slashes breakable in text for html.
- oxford_comma_implode() : mixed
- Implode an array of words according to the oxford comma rule.
- remove_stopwords() : mixed
- Remove stopwords.
- uuidv4() : string
- Generate a UUIDv4
- valid_email() : bool
- Verify that an email is well formed.
- valid_issn() : bool
- Verify that an issn is well formed.
- valid_uuidv4() : string
- Validate v4 UUID
Properties
$stop_words
Array of stopwords.
public
static array<string|int, mixed>
$stop_words
= array('a', 'an', 'the', 'on', 'for', 'with', 'at', 'by', 'and')
Array of stopwords.
Tags
Methods
array_mean()
Compute the mean
public
static array_mean(array<string|int, mixed> $array) : int|float
Parameters
- $array : array<string|int, mixed>
-
Array for which to compute the mean.
Tags
Return values
int|float —Mean of the array.
array_median()
Compute the median.
public
static array_median(array<string|int, mixed> $array) : float|int
Parameters
- $array : array<string|int, mixed>
-
Array for which to compute the standard deviation.
Tags
Return values
float|int —Median of the array.
array_stddev()
Compute the standard deviation
public
static array_stddev(array<string|int, mixed> $array) : float
Parameters
- $array : array<string|int, mixed>
-
Array for which to compute the standard deviation.
Tags
Return values
float —Standard deviation of the array.
base_convert_arbitrary_precision()
Arbitrary precision base_convert().
public
static base_convert_arbitrary_precision(string $str, int $frombase, int $tobase) : mixed
Similar to PHPs base_convert() but with arbitrary precision. Taken from http://php.net/manual/en/function.base-convert.php.
Parameters
- $str : string
-
String representation of the number to covert.
- $frombase : int
-
Base the input number is represented in.
- $tobase : int
-
Base to with the number is to be converted.
Tags
check_orcid()
Check that the given ORCID is well formated.
public
static check_orcid(string $orcid) : mixed
Verifies whether the given ORCID has a valid checksum.
Return true if the $orcid is a valid ORCID and otherwise a string describing why it is not valid.
Parameters
- $orcid : string
-
ORCID to check
Tags
is_assoc()
Test whether an array is associative or enumerated.
public
static is_assoc(array<string|int, mixed> $a) : bool
Parameters
- $a : array<string|int, mixed>
-
Array to test.
Return values
bool —Whether the array is associative or not.
make_slash_breakable_html()
Make slashes breakable in text for html.
public
static make_slash_breakable_html(string $string) : mixed
There is no way to break long lines with css or html that works consistently in all browsers. We are hence making long urls breakable by adding zero width space characters afert every /. This does not seem to have any adverse side-effects as the zero-width characters are ignored when a link text is copied and pasted.
Parameters
- $string : string
-
String in which slashes are to be made breakable.
Tags
oxford_comma_implode()
Implode an array of words according to the oxford comma rule.
public
static oxford_comma_implode(array<string|int, mixed> $array) : mixed
Parameters
- $array : array<string|int, mixed>
-
Array of strings to be imploded with Oxford commas.
Tags
remove_stopwords()
Remove stopwords.
public
static remove_stopwords(string $text) : mixed
Removes the stopwords in static::stop_words from $text and tries to avoid the creation of double spaces.
Parameters
- $text : string
-
Text from which stopwords are to be removed.
Tags
uuidv4()
Generate a UUIDv4
public
static uuidv4() : string
Code is taken from https://stackoverflow.com/a/15875555
Tags
Return values
string —A v4 UUID
valid_email()
Verify that an email is well formed.
public
static valid_email(string $email) : bool
Parameters
- $email : string
-
Email to be checked
Tags
Return values
bool —Whether $email is well formed.
valid_issn()
Verify that an issn is well formed.
public
static valid_issn(string $issn) : bool
Parameters
- $issn : string
-
ISSN to be checked
Tags
Return values
bool —Whether $issn is well formed.
valid_uuidv4()
Validate v4 UUID
public
static valid_uuidv4(mixed $uuid) : string
Parameters
- $uuid : mixed
Tags
Return values
string —A v4 UUID