21 public static function subStr(
string $a_str,
int $a_start, ?
int $a_length =
null): string
23 if (function_exists(
"mb_substr")) {
26 if ($a_length ===
null) {
27 $a_length = mb_strlen($a_str,
"UTF-8");
30 return mb_substr($a_str, $a_start, $a_length,
"UTF-8");
32 return substr($a_str, $a_start, $a_length);
39 public static function strPos(
string $a_haystack,
string $a_needle,
int $a_offset = 0)
41 if (function_exists(
"mb_strpos")) {
42 return mb_strpos($a_haystack, $a_needle, $a_offset,
"UTF-8");
44 return strpos($a_haystack, $a_needle, $a_offset);
51 public static function strIPos(
string $a_haystack,
string $a_needle,
int $a_offset = 0)
53 if (function_exists(
"mb_stripos")) {
54 return mb_stripos($a_haystack, $a_needle, $a_offset,
"UTF-8");
56 return stripos($a_haystack, $a_needle, $a_offset);
60 public static function strLen(
string $a_string):
int 62 if (function_exists(
"mb_strlen")) {
63 return mb_strlen($a_string,
"UTF-8");
65 return strlen($a_string);
69 public static function strToLower(
string $a_string): string
71 if (function_exists(
"mb_strtolower")) {
72 return mb_strtolower($a_string,
"UTF-8");
74 return strtolower($a_string);
78 public static function strToUpper(
string $a_string): string
80 if (function_exists(
"mb_strtoupper")) {
81 return mb_strtoupper($a_string,
"UTF-8");
83 return strtoupper($a_string);
103 string $a_encoding =
'UTF-8' 105 if (function_exists(
"mb_strcut")) {
106 return mb_strcut($a_string, $a_start_pos, $a_num_bytes, $a_encoding);
108 return substr($a_string, $a_start_pos, $a_num_bytes);
114 public static function isUtf8(
string $a_str): bool
116 if (function_exists(
"mb_detect_encoding")) {
117 if (mb_detect_encoding($a_str,
"UTF-8",
true) ===
"UTF-8") {
125 $len = strlen($a_str);
126 for ($i = 0; $i < $len; $i++) {
127 $c = ord($a_str[$i]);
131 } elseif (
$c >= 252) {
133 } elseif (
$c >= 248) {
135 } elseif (
$c >= 240) {
137 } elseif (
$c >= 224) {
139 } elseif (
$c >= 192) {
144 if (($i + $bits) > $len) {
149 $b = ord($a_str[$i]);
150 if ($b < 128 || $b > 191) {
172 [
'#(?<=(?:[A-Z]))([A-Z]+)([A-Z][A-z])#',
'#(?<=(?:[a-z0-9]))([A-Z])#'],
185 bool $a_dots =
false,
186 bool $a_next_blank =
false,
187 bool $a_keep_extension =
false 209 if ($a_keep_extension) {
210 $p = strrpos($a_str,
'.');
212 if ($p ===
false || $p == 0 || strlen($a_str) - $p > $a_len) {
215 $a_str .=
"\xe2\x80\xa6";
219 $a_str =
ilStr::subStr($a_str, 0, $len - (strlen($a_str) - $p + 1)) .
"\xe2\x80\xa6" . substr(
224 $a_str =
ilStr::subStr($a_str, 0, $len - (strlen($a_str) - $p + 1)) . substr($a_str, $p);
238 public static function shortenWords(
string $a_str,
int $a_len = 30,
bool $a_dots =
true): string
240 $str_arr = explode(
" ", $a_str);
242 for ($i = 0; $i < count($str_arr); $i++) {
246 $str_arr[$i] .=
"...";
251 return implode(
" ", $str_arr);
static strIPos(string $a_haystack, string $a_needle, int $a_offset=0)
static convertUpperCamelCaseToUnderscoreCase(string $value)
Convert a value given in camel case conversion to underscore case conversion (e.g.
static strPos(string $a_haystack, string $a_needle, int $a_offset=0)
static subStr(string $a_str, int $a_start, ?int $a_length=null)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static strLen(string $a_string)
static shortenText(string $a_string, int $a_start_pos, int $a_num_bytes, string $a_encoding='UTF-8')
Shorten text to the given number of bytes.
static strToUpper(string $a_string)
static isUtf8(string $a_str)
Check whether string is utf-8.
static strCmp(string $a, string $b)
static shortenTextExtended(string $a_str, int $a_len, bool $a_dots=false, bool $a_next_blank=false, bool $a_keep_extension=false)
static strToLower(string $a_string)
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
static shortenWords(string $a_str, int $a_len=30, bool $a_dots=true)
Ensure that the maximum word lenght within a text is not longer than $a_len.