ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Extract.php
Go to the documentation of this file.
1<?php
2
4
7
8class Extract
9{
16 public static function left($value = '', $chars = 1): string
17 {
18 $value = Functions::flattenSingleValue($value);
19 $chars = Functions::flattenSingleValue($chars);
20
21 if (!is_numeric($chars) || $chars < 0) {
22 return Functions::VALUE();
23 }
24
25 if (is_bool($value)) {
26 $value = ($value) ? Calculation::getTRUE() : Calculation::getFALSE();
27 }
28
29 return mb_substr($value, 0, $chars, 'UTF-8');
30 }
31
39 public static function mid($value = '', $start = 1, $chars = null): string
40 {
41 $value = Functions::flattenSingleValue($value);
43 $chars = Functions::flattenSingleValue($chars);
44
45 if (!is_numeric($start) || $start < 1 || !is_numeric($chars) || $chars < 0) {
46 return Functions::VALUE();
47 }
48
49 if (is_bool($value)) {
50 $value = ($value) ? Calculation::getTRUE() : Calculation::getFALSE();
51 }
52
53 return mb_substr($value, --$start, $chars, 'UTF-8');
54 }
55
62 public static function right($value = '', $chars = 1): string
63 {
64 $value = Functions::flattenSingleValue($value);
65 $chars = Functions::flattenSingleValue($chars);
66
67 if (!is_numeric($chars) || $chars < 0) {
68 return Functions::VALUE();
69 }
70
71 if (is_bool($value)) {
72 $value = ($value) ? Calculation::getTRUE() : Calculation::getFALSE();
73 }
74
75 return mb_substr($value, mb_strlen($value, 'UTF-8') - $chars, $chars, 'UTF-8');
76 }
77}
An exception for terminatinating execution or to throw for unit testing.
static getTRUE()
Return the locale-specific translation of TRUE.
static getFALSE()
Return the locale-specific translation of FALSE.
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.
Definition: Functions.php:649
static right($value='', $chars=1)
RIGHT.
Definition: Extract.php:62
static left($value='', $chars=1)
LEFT.
Definition: Extract.php:16
static mid($value='', $start=1, $chars=null)
MID.
Definition: Extract.php:39
$start
Definition: bench.php:8