ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilStr Class Reference

Multi byte sensitive string functions. More...

+ Collaboration diagram for ilStr:

Static Public Member Functions

static subStr ($a_str, $a_start, $a_length=null)
 
static strPos ($a_haystack, $a_needle, $a_offset=null)
 
static strrPos ($a_haystack, $a_needle, $a_offset=null)
 
static strIPos ($a_haystack, $a_needle, $a_offset=null)
 
static strLen ($a_string)
 
static strToLower ($a_string)
 
static strToUpper ($a_string)
 
static strCmp ($a, $b)
 Compare two strings. More...
 
static shortenText ($a_string, $a_start_pos, $a_num_bytes, $a_encoding='UTF-8')
 Shorten text to the given number of bytes. More...
 
static isUtf8 ($a_str)
 Check whether string is utf-8. More...
 
static strPosAll ($a_haystack, $a_needle)
 Get all positions of a string. More...
 
static replaceFirsOccurence ($a_old, $a_new, $a_str)
 Replaces the first occurence of $a_old in $a_str with $a_new. More...
 
static convertUpperCamelCaseToUnderscoreCase ($value)
 Convert a value given in camel case conversion to underscore case conversion (e.g. More...
 
static getBytesForString ($a_str)
 Return string as byte array Note: Use this for debugging purposes only. More...
 
static normalizeUtf8String ($a_str)
 Normalize UTF8 string. More...
 

Detailed Description

Multi byte sensitive string functions.

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Helmut Schottmüller helmu.nosp@m.t.sc.nosp@m.hottm.nosp@m.uell.nosp@m.er@ma.nosp@m.c.co.nosp@m.m
Version
$Id$

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

Member Function Documentation

◆ convertUpperCamelCaseToUnderscoreCase()

static ilStr::convertUpperCamelCaseToUnderscoreCase (   $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 232 of file class.ilStr.php.

Referenced by ilAbstractBuddySystemRelationStateButtonRenderer\__construct(), ilContactUserActionProvider\collectActionsForTargetUser(), ilAbstractBuddySystemRelationStateButtonRenderer\renderStateButton(), ilAbstractBuddySystemRelationStateButtonRenderer\renderTargetState(), ilMailSearchGroupsGUI\showMembers(), and ilMailSearchCoursesGUI\showMembers().

233  {
234  return strtolower(preg_replace(
235  array('#(?<=(?:[A-Z]))([A-Z]+)([A-Z][A-z])#', '#(?<=(?:[a-z0-9]))([A-Z])#'),
236  array('\1_\2', '_\1'),
237  $value
238  ));
239  }
+ Here is the caller graph for this function:

◆ getBytesForString()

static ilStr::getBytesForString (   $a_str)
static

Return string as byte array Note: Use this for debugging purposes only.

If strlen is overwritten by mb_ functions (PHP config) this will return not all characters

Parameters
string$a_strstring
Returns
array array of bytes

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

References $i.

Referenced by ilObjFile\createProperties().

250  {
251  $bytes = array();
252  for ($i = 0; $i < strlen($a_str); $i++) {
253  $bytes[] = ord($a_str[$i]);
254  }
255  return $bytes;
256  }
$i
Definition: disco.tpl.php:19
+ Here is the caller graph for this function:

◆ isUtf8()

static ilStr::isUtf8 (   $a_str)
static

Check whether string is utf-8.

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

References $c, and $i.

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

150  {
151  if (function_exists("mb_detect_encoding")) {
152  if (mb_detect_encoding($a_str, "UTF-8", true) == "UTF-8") {
153  return true;
154  }
155  } else {
156  // copied from http://www.php.net/manual/en/function.mb-detect-encoding.php
157  $c = 0;
158  $b = 0;
159  $bits = 0;
160  $len = strlen($a_str);
161  for ($i = 0; $i < $len; $i++) {
162  $c = ord($a_str[$i]);
163  if ($c > 128) {
164  if (($c >= 254)) {
165  return false;
166  } elseif ($c >= 252) {
167  $bits = 6;
168  } elseif ($c >= 248) {
169  $bits = 5;
170  } elseif ($c >= 240) {
171  $bits = 4;
172  } elseif ($c >= 224) {
173  $bits = 3;
174  } elseif ($c >= 192) {
175  $bits = 2;
176  } else {
177  return false;
178  }
179  if (($i + $bits) > $len) {
180  return false;
181  }
182  while ($bits > 1) {
183  $i++;
184  $b = ord($a_str[$i]);
185  if ($b < 128 || $b > 191) {
186  return false;
187  }
188  $bits--;
189  }
190  }
191  }
192  return true;
193  }
194  return false;
195  }
$i
Definition: disco.tpl.php:19
+ Here is the caller graph for this function:

◆ normalizeUtf8String()

static ilStr::normalizeUtf8String (   $a_str)
static

Normalize UTF8 string.

Parameters
string$a_strstring
Returns
string

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

References UtfNormal\toNFC().

Referenced by ilFileWizardInputGUI\checkInput(), ilDragDropFileInputGUI\checkInput(), and ilFileInputGUI\checkInput().

265  {
266  include_once("./include/Unicode/UtfNormal.php");
267  return UtfNormal::toNFC($a_str);
268  }
static toNFC($string)
Convert a UTF-8 string to normal form C, canonical composition.
Definition: UtfNormal.php:157
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ replaceFirsOccurence()

static ilStr::replaceFirsOccurence (   $a_old,
  $a_new,
  $a_str 
)
static

Replaces the first occurence of $a_old in $a_str with $a_new.

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

Referenced by ilPageObjectGUI\insertPageToc().

220  {
221  if (is_int(strpos($a_str, $a_old))) {
222  $a_str = substr_replace($a_str, $a_new, strpos($a_str, $a_old), strlen($a_old));
223  }
224  return $a_str;
225  }
+ Here is the caller graph for this function:

◆ shortenText()

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

Shorten text to the given number of bytes.

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

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

Parameters
string$a_string
int$a_start_pos
int$a_num_bytes
string$a_encoding[optional]
Returns
string

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

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

139  {
140  if (function_exists("mb_strcut")) {
141  return mb_strcut($a_string, $a_start_pos, $a_num_bytes, $a_encoding);
142  }
143  return substr($a_string, $a_start_pos, $a_num_bytes);
144  }
+ Here is the caller graph for this function:

◆ strCmp()

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

Compare two strings.

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

References $DIC, and strToUpper().

Referenced by ilUtil\sort_func().

110  {
111  global $DIC;
112 
113  $ilCollator = null;
114  if (isset($DIC["ilCollator"])) {
115  $ilCollator = $DIC["ilCollator"];
116  }
117 
118  if (is_object($ilCollator)) {
119  return ($ilCollator->compare(ilStr::strToUpper($a), ilStr::strToUpper($b)) > 0);
120  } else {
121  return (strcoll(ilStr::strToUpper($a), ilStr::strToUpper($b)) > 0);
122  }
123  }
global $DIC
Definition: saml.php:7
static strToUpper($a_string)
Definition: class.ilStr.php:96
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ strIPos()

static ilStr::strIPos (   $a_haystack,
  $a_needle,
  $a_offset = null 
)
static

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

Referenced by ilMathJax\insertLatexImages(), and ilPCParagraph\linkTermsInDom().

49  {
50  if (function_exists("mb_stripos")) {
51  return mb_stripos($a_haystack, $a_needle, $a_offset, "UTF-8");
52  } else {
53  return stripos($a_haystack, $a_needle, $a_offset);
54  }
55  }
+ Here is the caller graph for this function:

◆ strLen()

◆ strPos()

static ilStr::strPos (   $a_haystack,
  $a_needle,
  $a_offset = null 
)
static

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

Referenced by ilMathJax\insertLatexImages(), assTextQuestion\isKeywordMatching(), ilPCParagraph\linkTermsInDom(), ilUtil\shortenText(), assOrderingHorizontal\splitAndTrimOrderElementText(), and ilMailAutoCompleteSentMailsRecipientsProvider\valid().

31  {
32  if (function_exists("mb_strpos")) {
33  return mb_strpos($a_haystack, $a_needle, $a_offset, "UTF-8");
34  } else {
35  return strpos($a_haystack, $a_needle, $a_offset);
36  }
37  }
+ Here is the caller graph for this function:

◆ strPosAll()

static ilStr::strPosAll (   $a_haystack,
  $a_needle 
)
static

Get all positions of a string.

Parameters
stringthe string to search in
stringthe string to search for
Returns
array all occurences of needle in haystack

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

Referenced by ilPageObjectGUI\insertPageToc().

206  {
207  $positions = array();
208  $cpos = 0;
209  while (is_int($pos = strpos($a_haystack, $a_needle, $cpos))) {
210  $positions[] = $pos;
211  $cpos = $pos + 1;
212  }
213  return $positions;
214  }
+ Here is the caller graph for this function:

◆ strrPos()

static ilStr::strrPos (   $a_haystack,
  $a_needle,
  $a_offset = null 
)
static

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

Referenced by ilPCParagraph\linkTermsInDom().

40  {
41  if (function_exists("mb_strpos")) {
42  return mb_strrpos($a_haystack, $a_needle, $a_offset, "UTF-8");
43  } else {
44  return strrpos($a_haystack, $a_needle, $a_offset);
45  }
46  }
+ Here is the caller graph for this function:

◆ strToLower()

static ilStr::strToLower (   $a_string)
static

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

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

88  {
89  if (function_exists("mb_strtolower")) {
90  return mb_strtolower($a_string, "UTF-8");
91  } else {
92  return strtolower($a_string);
93  }
94  }
+ Here is the caller graph for this function:

◆ strToUpper()

static ilStr::strToUpper (   $a_string)
static

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

Referenced by ilUtil\sort_func(), and strCmp().

97  {
98  $a_string = (string) $a_string;
99  if (function_exists("mb_strtoupper")) {
100  return mb_strtoupper($a_string, "UTF-8");
101  } else {
102  return strtoupper($a_string);
103  }
104  }
+ Here is the caller graph for this function:

◆ subStr()

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

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

Referenced by ilObjQuestionPool\_getFullPathToQpl(), ilSCORMCertificateAdapter\addAdditionalFormElements(), ilICalWriter\addLine(), ilCertificateSettingsScormFormRepository\createForm(), ilObjUser\getPersonalPicturePath(), ilForumAuthorInformation\getUserImagePath(), ilForumAuthorInformation\init(), ilMathJax\insertLatexImages(), ilPCParagraph\linkTermsInDom(), ilChatroomViewGUI\lostConnection(), ilObjForumAccess\prepareMessageForLists(), SurveyTextQuestion\saveUserInput(), ilBiblFileReaderBase\setPathToFile(), ilAssQuestionSkillAssignmentRegistry\setStringifiedImports(), ilUtil\shortenText(), and ilUtil\shortenWords().

16  {
17  if (function_exists("mb_substr")) {
18  // bug in PHP < 5.4.12: null is not supported as length (if encoding given)
19  // https://github.com/php/php-src/pull/133
20  if ($a_length === null) {
21  $a_length = mb_strlen($a_str, "UTF-8");
22  }
23 
24  return mb_substr($a_str, $a_start, $a_length, "UTF-8");
25  } else {
26  return substr($a_str, $a_start, $a_length);
27  }
28  }
+ Here is the caller graph for this function:

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