ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilStr Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilStr:

Static Public Member Functions

static subStr (string $a_str, int $a_start, ?int $a_length=null)
 
static strPos (string $a_haystack, string $a_needle, ?int $a_offset=null)
 
static strIPos (string $a_haystack, string $a_needle, ?int $a_offset=null)
 
static strLen (string $a_string)
 
static strToLower (string $a_string)
 
static strToUpper (string $a_string)
 
static strCmp (string $a, string $b)
 
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. More...
 
static isUtf8 (string $a_str)
 Check whether string is utf-8. More...
 
static convertUpperCamelCaseToUnderscoreCase (string $value)
 Convert a value given in camel case conversion to underscore case conversion (e.g. More...
 
static shortenTextExtended (string $a_str, int $a_len, bool $a_dots=false, bool $a_next_blank=false, bool $a_keep_extension=false)
 
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. More...
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning

Deprecated:

Definition at line 22 of file class.ilStr.php.

Member Function Documentation

◆ convertUpperCamelCaseToUnderscoreCase()

static ilStr::convertUpperCamelCaseToUnderscoreCase ( string  $value)
static

Convert a value given in camel case conversion to underscore case conversion (e.g.

MyClass to my_class)

Parameters
string$valueValue in lower camel case conversion
Returns
string The value in underscore case conversion

Definition at line 171 of file class.ilStr.php.

Referenced by ilAbstractBuddySystemRelationStateButtonRenderer\__construct(), ilMailSearchObjectGUI\cancel(), ilContactUserActionProvider\collectActionsForTargetUser(), ilAbstractBuddySystemRelationStateButtonRenderer\renderStateButton(), and ilAbstractBuddySystemRelationStateButtonRenderer\renderTargetState().

171  : string
172  {
173  return strtolower(
174  preg_replace(
175  ['#(?<=(?:[A-Z]))([A-Z]+)([A-Z][A-z])#', '#(?<=(?:[a-z0-9]))([A-Z])#'],
176  ['\1_\2', '_\1'],
177  $value
178  )
179  );
180  }
+ Here is the caller graph for this function:

◆ isUtf8()

static ilStr::isUtf8 ( string  $a_str)
static

Check whether string is utf-8.

Definition at line 117 of file class.ilStr.php.

References Vendor\Package\$b, $c, and $i.

Referenced by ilObjLanguage\check(), ilDclTextFieldModel\checkTitlesForImport(), and ilDclBaseFieldModel\checkTitlesForImport().

117  : bool
118  {
119  if (function_exists("mb_detect_encoding")) {
120  if (mb_detect_encoding($a_str, "UTF-8", true) === "UTF-8") {
121  return true;
122  }
123  } else {
124  // copied from http://www.php.net/manual/en/function.mb-detect-encoding.php
125  $c = 0;
126  $b = 0;
127  $bits = 0;
128  $len = strlen($a_str);
129  for ($i = 0; $i < $len; $i++) {
130  $c = ord($a_str[$i]);
131  if ($c > 128) {
132  if (($c >= 254)) {
133  return false;
134  } elseif ($c >= 252) {
135  $bits = 6;
136  } elseif ($c >= 248) {
137  $bits = 5;
138  } elseif ($c >= 240) {
139  $bits = 4;
140  } elseif ($c >= 224) {
141  $bits = 3;
142  } elseif ($c >= 192) {
143  $bits = 2;
144  } else {
145  return false;
146  }
147  if (($i + $bits) > $len) {
148  return false;
149  }
150  while ($bits > 1) {
151  $i++;
152  $b = ord($a_str[$i]);
153  if ($b < 128 || $b > 191) {
154  return false;
155  }
156  $bits--;
157  }
158  }
159  }
160  return true;
161  }
162  return false;
163  }
$c
Definition: cli.php:38
$i
Definition: metadata.php:41
+ Here is the caller graph for this function:

◆ shortenText()

static ilStr::shortenText ( string  $a_string,
int  $a_start_pos,
int  $a_num_bytes,
string  $a_encoding = 'UTF-8' 
)
static

Shorten text to the given number of bytes.

If the character is cut within a character the invalid character will be shortened, too.

E.g: shortenText('€€€',4) will return '€'

Definition at line 102 of file class.ilStr.php.

Referenced by ilDBGenerator\shortenText(), and ilPageObject\truncateHTML().

107  : string {
108  if (function_exists("mb_strcut")) {
109  return mb_strcut($a_string, $a_start_pos, $a_num_bytes, $a_encoding);
110  }
111  return substr($a_string, $a_start_pos, $a_num_bytes);
112  }
+ Here is the caller graph for this function:

◆ shortenTextExtended()

static ilStr::shortenTextExtended ( string  $a_str,
int  $a_len,
bool  $a_dots = false,
bool  $a_next_blank = false,
bool  $a_keep_extension = false 
)
static
Deprecated:

Definition at line 185 of file class.ilStr.php.

References strLen(), strPos(), and subStr().

Referenced by ilObjSystemFolder\_getHeaderTitleDescription(), ilObject\_writeDescription(), ilExcel\addSheet(), ilStudyProgrammeDashboardViewGUI\buildItem(), ilObjSystemFolder\delete(), ilObjWikiGUI\editImportantPagesObject(), ilTree\fetchNodeData(), ilLDAPRoleMappingTableGUI\fillRow(), ilNewsForContextTableGUI\fillRow(), ilAssignmentsTableGUI\fillRow(), ilAdminSubItemsTableGUI\fillRow(), ilPresentationListTableGUI\fillRow(), ilTermListTableGUI\fillRow(), ilECSNodeMappingCmsExplorer\formatObject(), ilECSNodeMappingLocalExplorer\formatObject(), ilPasteIntoMultipleItemsExplorer\formatObject(), ilExplorer\formatObject(), SurveyMatrixQuestionEvaluation\getChart(), ilContainer\getCompleteDescriptions(), ilObjLinkResourceListGUI\getDescription(), ilPDSelectedItemsBlockSelectedItemsProvider\getItems(), ilDashboardRecommendedContentGUI\getListItemGroups(), ilPDSelectedItemsBlockMembershipsProvider\getObjectsByMembership(), ilMailNotification\getObjectTitle(), ilCalendarEntry\getPresentationTitle(), ilLMPresentationGUI\ilLocator(), ilObjWikiGUI\initSettingsForm(), ilSCORMExplorer\insertObject(), ilWikiPageTemplateGUI\listTemplates(), ilChartDataSpider\parseGlobalOptions(), ilLMNavigationRendererGUI\render(), ILIAS\Repository\Provider\RepositoryMainBarProvider\renderLastVisited(), ilMembershipCronNotifications\run(), ilObject\setDescription(), ilObject\setTitle(), and ilGlossaryDefinition\shortenShortText().

191  : string {
192  if (ilStr::strLen($a_str) > $a_len) {
193  /*
194  * When adding dots, the dots have to be included in the length such
195  * that the total length of the resulting string does not exceed
196  * the given maximum length (see BT 33865).
197  */
198  if ($a_dots) {
199  $a_len--;
200  }
201  if ($a_next_blank) {
202  $len = ilStr::strPos($a_str, " ", $a_len);
203  } else {
204  $len = $a_len;
205  }
206  // BEGIN WebDAV
207  // - Shorten names in the middle, before the filename extension
208  // Workaround for Windows WebDAV Client:
209  // Use the unicode ellipsis symbol for shortening instead of
210  // three full stop characters.
211  $p = false;
212  if ($a_keep_extension) {
213  $p = strrpos($a_str, '.'); // this messes up normal shortening, see bug #6190
214  }
215  if ($p === false || $p == 0 || strlen($a_str) - $p > $a_len) {
216  $a_str = ilStr::subStr($a_str, 0, $len);
217  if ($a_dots) {
218  $a_str .= "\xe2\x80\xa6"; // UTF-8 encoding for Unicode ellipsis character.
219  }
220  } else {
221  if ($a_dots) {
222  $a_str = ilStr::subStr($a_str, 0, $len - (strlen($a_str) - $p + 1)) . "\xe2\x80\xa6" . substr(
223  $a_str,
224  $p
225  );
226  } else {
227  $a_str = ilStr::subStr($a_str, 0, $len - (strlen($a_str) - $p + 1)) . substr($a_str, $p);
228  }
229  }
230  }
231 
232  return $a_str;
233  }
static strPos(string $a_haystack, string $a_needle, ?int $a_offset=null)
Definition: class.ilStr.php:42
static subStr(string $a_str, int $a_start, ?int $a_length=null)
Definition: class.ilStr.php:24
static strLen(string $a_string)
Definition: class.ilStr.php:63
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ shortenWords()

static ilStr::shortenWords ( string  $a_str,
int  $a_len = 30,
bool  $a_dots = true 
)
static

Ensure that the maximum word lenght within a text is not longer than $a_len.

Definition at line 241 of file class.ilStr.php.

References $i, strLen(), and subStr().

Referenced by ilNewsForContextBlockGUI\getInfoForData(), and ilCalendarEntry\getPresentationTitle().

241  : string
242  {
243  $str_arr = explode(" ", $a_str);
244 
245  for ($i = 0; $i < count($str_arr); $i++) {
246  if (ilStr::strLen($str_arr[$i]) > $a_len) {
247  $str_arr[$i] = ilStr::subStr($str_arr[$i], 0, $a_len);
248  if ($a_dots) {
249  $str_arr[$i] .= "...";
250  }
251  }
252  }
253 
254  return implode(" ", $str_arr);
255  }
static subStr(string $a_str, int $a_start, ?int $a_length=null)
Definition: class.ilStr.php:24
static strLen(string $a_string)
Definition: class.ilStr.php:63
$i
Definition: metadata.php:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ strCmp()

static ilStr::strCmp ( string  $a,
string  $b 
)
static

Definition at line 90 of file class.ilStr.php.

References strToUpper().

Referenced by ilArrayUtil\sort_func().

90  : int
91  {
92  return strcoll(ilStr::strToUpper($a), ilStr::strToUpper($b));
93  }
static strToUpper(string $a_string)
Definition: class.ilStr.php:81
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ strIPos()

static ilStr::strIPos ( string  $a_haystack,
string  $a_needle,
?int  $a_offset = null 
)
static
Returns
false|int

Definition at line 54 of file class.ilStr.php.

Referenced by ilCronManagerTableFilterMediator\filteredJobs(), ilMathJax\insertLatexImages(), ilDidacticTemplateSettingsTableFilter\isFiltered(), and ilPCParagraph\linkTermsInDom().

55  {
56  if (function_exists("mb_stripos")) {
57  return mb_stripos($a_haystack, $a_needle, $a_offset ?? 0, "UTF-8");
58  } else {
59  return stripos($a_haystack, $a_needle, $a_offset);
60  }
61  }
+ Here is the caller graph for this function:

◆ strLen()

◆ strPos()

static ilStr::strPos ( string  $a_haystack,
string  $a_needle,
?int  $a_offset = null 
)
static
Returns
false|int|true

Definition at line 42 of file class.ilStr.php.

Referenced by assTextQuestion\isKeywordMatching(), ilPCParagraph\linkTermsInDom(), shortenTextExtended(), assOrderingHorizontal\splitAndTrimOrderElementText(), and ilMailAutoCompleteSentMailsRecipientsProvider\valid().

43  {
44  if (function_exists("mb_strpos")) {
45  return mb_strpos($a_haystack, $a_needle, $a_offset, "UTF-8");
46  } else {
47  return strpos($a_haystack, $a_needle, $a_offset);
48  }
49  }
+ Here is the caller graph for this function:

◆ strToLower()

static ilStr::strToLower ( string  $a_string)
static

Definition at line 72 of file class.ilStr.php.

Referenced by assClozeTest\getTextgapPoints(), ilAuthProviderSaml\importUser(), assTextSubset\isAnswerCorrect(), assTextQuestion\isKeywordMatching(), and ilMailAutoCompleteSentMailsRecipientsProvider\valid().

72  : string
73  {
74  if (function_exists("mb_strtolower")) {
75  return mb_strtolower($a_string, "UTF-8");
76  } else {
77  return strtolower($a_string);
78  }
79  }
+ Here is the caller graph for this function:

◆ strToUpper()

static ilStr::strToUpper ( string  $a_string)
static

Definition at line 81 of file class.ilStr.php.

Referenced by ilUserDefinedFieldsPlaceholderDescription\__construct(), ilObjectCustomUserFieldsPlaceholderValues\__construct(), ilUserDefinedFieldsPlaceholderValues\__construct(), ilObjectCustomUserFieldsPlaceholderValues\getPlaceholderValuesForPreview(), ilUserDefinedFieldsPlaceholderValues\getPlaceholderValuesForPreview(), ilObjectCustomUserFieldsPlaceholderDescription\initPlaceholders(), and strCmp().

81  : string
82  {
83  if (function_exists("mb_strtoupper")) {
84  return mb_strtoupper($a_string, "UTF-8");
85  } else {
86  return strtoupper($a_string);
87  }
88  }
+ Here is the caller graph for this function:

◆ subStr()

static ilStr::subStr ( string  $a_str,
int  $a_start,
?int  $a_length = null 
)
static

The documentation for this class was generated from the following file: