ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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=0)
 
static strIPos (string $a_haystack, string $a_needle, int $a_offset=0)
 
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

Definition at line 19 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 168 of file class.ilStr.php.

168 : string
169 {
170 return strtolower(
171 preg_replace(
172 ['#(?<=(?:[A-Z]))([A-Z]+)([A-Z][A-z])#', '#(?<=(?:[a-z0-9]))([A-Z])#'],
173 ['\1_\2', '_\1'],
174 $value
175 )
176 );
177 }

Referenced by ilAbstractBuddySystemRelationStateButtonRenderer\__construct(), ilContactUserActionProvider\collectActionsForTargetUser(), ilAbstractBuddySystemRelationState\getSnakeName(), ilAbstractBuddySystemRelationStateButtonRenderer\renderStateButton(), and ilAbstractBuddySystemRelationStateButtonRenderer\renderTargetState().

+ 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 114 of file class.ilStr.php.

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

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

Referenced by ilObjLanguage\check().

+ 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 99 of file class.ilStr.php.

104 : string {
105 if (function_exists("mb_strcut")) {
106 return mb_strcut($a_string, $a_start_pos, $a_num_bytes, $a_encoding);
107 }
108 return substr($a_string, $a_start_pos, $a_num_bytes);
109 }

Referenced by ilPageObject\truncateHTML().

+ 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 182 of file class.ilStr.php.

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

References strPos(), and subStr().

Referenced by ilObjSystemFolder\_getHeaderTitleDescription(), ilObject\_writeDescription(), ilObjWikiGUI\editImportantPagesObject(), ilTree\fetchNodeData(), ilBookingReservationsTableGUI\fillRow(), ilAssignmentsTableGUI\fillRow(), ilNewsForContextTableGUI\fillRow(), ilAdminSubItemsTableGUI\fillRow(), ilECSNodeMappingCmsExplorer\formatObject(), ilECSNodeMappingLocalExplorer\formatObject(), ilPasteIntoMultipleItemsExplorer\formatObject(), SurveyMatrixQuestionEvaluation\getChart(), ILIAS\Container\Content\ItemSetManager\getCompleteDescriptions(), ilContainer\getCompleteDescriptions(), ILIAS\components\ILIAS\Glossary\Table\TermListTable\getDataRetrieval(), ilObjLinkResourceListGUI\getDescription(), ilPDSelectedItemsBlockSelectedItemsProvider\getItems(), ilPDSelectedItemsBlockMembershipsProvider\getObjectsByMembership(), ilMailNotification\getObjectTitle(), ilCalendarEntry\getPresentationTitle(), ilPresentationTableGUI\getShortTextForTerm(), ILIAS\Wiki\Settings\SettingsManager\getStartPageOptions(), ilLMPresentationGUI\ilLocator(), ilDashboardRecommendedContentGUI\initData(), LDAPRoleMappingTable\initRecords(), ilSCORMExplorer\insertObject(), ilWikiPageTemplateGUI\listTemplates(), ilChartDataSpider\parseGlobalOptions(), ilLMNavigationRendererGUI\render(), ILIAS\Repository\Provider\RepositoryMainBarProvider\renderLastVisited(), ilObject\setTitle(), and ilGlossaryTerm\shortenShortText().

+ 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.

@depends

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

238 : string
239 {
240 $str_arr = explode(" ", $a_str);
241
242 for ($i = 0; $i < count($str_arr); $i++) {
243 if (ilStr::strLen($str_arr[$i]) > $a_len) {
244 $str_arr[$i] = ilStr::subStr($str_arr[$i], 0, $a_len);
245 if ($a_dots) {
246 $str_arr[$i] .= "...";
247 }
248 }
249 }
250
251 return implode(" ", $str_arr);
252 }

References strLen(), and subStr().

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

+ 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

◆ strIPos()

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

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

52 {
53 if (function_exists("mb_stripos")) {
54 return mb_stripos($a_haystack, $a_needle, $a_offset, "UTF-8");
55 } else {
56 return stripos($a_haystack, $a_needle, $a_offset);
57 }
58 }

Referenced by ILIAS\Cron\Job\Manager\UI\JobTableFilterMediator\filteredJobs(), ilDidacticTemplateSettingsTableFilter\isFiltered(), and ilRTE\replaceLatexSpan().

+ Here is the caller graph for this function:

◆ strLen()

◆ strPos()

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

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

40 {
41 if (function_exists("mb_strpos")) {
42 return mb_strpos($a_haystack, $a_needle, $a_offset, "UTF-8");
43 } else {
44 return strpos($a_haystack, $a_needle, $a_offset);
45 }
46 }

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

+ Here is the caller graph for this function:

◆ strToLower()

static ilStr::strToLower ( string  $a_string)
static

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

69 : string
70 {
71 if (function_exists("mb_strtolower")) {
72 return mb_strtolower($a_string, "UTF-8");
73 } else {
74 return strtolower($a_string);
75 }
76 }

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

+ Here is the caller graph for this function:

◆ strToUpper()

static ilStr::strToUpper ( string  $a_string)
static

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

78 : string
79 {
80 if (function_exists("mb_strtoupper")) {
81 return mb_strtoupper($a_string, "UTF-8");
82 } else {
83 return strtoupper($a_string);
84 }
85 }

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

+ Here is the caller graph for this function:

◆ subStr()

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

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

21 : string
22 {
23 if (function_exists("mb_substr")) {
24 // bug in PHP < 5.4.12: null is not supported as length (if encoding given)
25 // https://github.com/php/php-src/pull/133
26 if ($a_length === null) {
27 $a_length = mb_strlen($a_str, "UTF-8");
28 }
29
30 return mb_substr($a_str, $a_start, $a_length, "UTF-8");
31 } else {
32 return substr($a_str, $a_start, $a_length);
33 }
34 }

Referenced by ilMailSearchObjectMembershipsTableGUI\__construct(), ilICalWriter\addLine(), ilCertificateSettingsScormFormRepository\createForm(), ilForumAuthorInformation\init(), ilBiblFileReaderBase\parseContentToEntries(), ilObjForumAccess\prepareMessageForLists(), ilUserAvatarResolver\readUserSettings(), ilRTE\replaceLatexSpan(), ilCertificateCron\run(), ilSurveyParticipantsGUI\sendCodesMailObject(), ilAssQuestionSkillAssignmentRegistry\setStringifiedImports(), ilMailNotification\setSubject(), shortenTextExtended(), shortenWords(), ILIAS\Refinery\String\Transformation\LevenshteinTransformation\stringToCharacterArray(), and ilChatroomViewGUI\userEntry().

+ Here is the caller graph for this function:

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