ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 246 of file class.ilStr.php.

References array.

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

247  {
248  return strtolower(preg_replace(
249  array('#(?<=(?:[A-Z]))([A-Z]+)([A-Z][A-z])#', '#(?<=(?:[a-z0-9]))([A-Z])#'),
250  array('\1_\2', '_\1'),
251  $value
252  ));
253  }
Create styles array
The data for the language used.
+ 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 263 of file class.ilStr.php.

References array.

Referenced by ilObjFile\createProperties().

264  {
265  $bytes = array();
266  for($i = 0; $i < strlen($a_str); $i++)
267  {
268  $bytes[] = ord($a_str[$i]);
269  }
270  return $bytes;
271  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ isUtf8()

static ilStr::isUtf8 (   $a_str)
static

Check whether string is utf-8.

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

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

171  {
172  if (function_exists("mb_detect_encoding"))
173  {
174  if (mb_detect_encoding($a_str, "UTF-8", true) == "UTF-8")
175  {
176  return true;
177  }
178  }
179  else
180  {
181  // copied from http://www.php.net/manual/en/function.mb-detect-encoding.php
182  $c=0; $b=0;
183  $bits=0;
184  $len=strlen($a_str);
185  for($i=0; $i<$len; $i++){
186  $c=ord($a_str[$i]);
187  if($c > 128){
188  if(($c >= 254)) return false;
189  elseif($c >= 252) $bits=6;
190  elseif($c >= 248) $bits=5;
191  elseif($c >= 240) $bits=4;
192  elseif($c >= 224) $bits=3;
193  elseif($c >= 192) $bits=2;
194  else return false;
195  if(($i+$bits) > $len) return false;
196  while($bits > 1){
197  $i++;
198  $b=ord($a_str[$i]);
199  if($b < 128 || $b > 191) return false;
200  $bits--;
201  }
202  }
203  }
204  return true;
205  }
206  return false;
207  }
if( $out) else
while(!file_exists( 'ilias.ini.php'))
Definition: latex.php:4
PHPExcel root directory.
Definition: Database.php:30
+ 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 279 of file class.ilStr.php.

References UtfNormal\toNFC().

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

280  {
281  include_once("./include/Unicode/UtfNormal.php");
282  return UtfNormal::toNFC($a_str);
283  }
static toNFC( $string)
Convert a UTF-8 string to normal form C, canonical composition.
Definition: UtfNormal.php:154
+ 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 232 of file class.ilStr.php.

Referenced by ilPageObjectGUI\insertPageToc().

233  {
234  if (is_int(strpos($a_str, $a_old)))
235  {
236  $a_str = substr_replace ($a_str, $a_new, strpos($a_str, $a_old), strlen($a_old));
237  }
238  return $a_str;
239  }
+ 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 158 of file class.ilStr.php.

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

159  {
160  if (function_exists("mb_strcut"))
161  {
162  return mb_strcut($a_string, $a_start_pos, $a_num_bytes, $a_encoding);
163  }
164  return substr($a_string, $a_start_pos, $a_num_bytes);
165  }
+ Here is the caller graph for this function:

◆ strCmp()

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

Compare two strings.

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

References strToUpper().

Referenced by ilUtil\sort_func().

132  {
133  global $ilCollator;
134 
135  if (is_object($ilCollator))
136  {
137  return ($ilCollator->compare(ilStr::strToUpper($a), ilStr::strToUpper($b)) > 0);
138  }
139  else
140  {
141  return (strcoll(ilStr::strToUpper($a), ilStr::strToUpper($b)) > 0);
142  }
143  }
static strToUpper($a_string)
+ 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 58 of file class.ilStr.php.

Referenced by ilPCParagraph\linkTermsInDom().

59  {
60  if (function_exists("mb_stripos"))
61  {
62  return mb_stripos($a_haystack, $a_needle, $a_offset, "UTF-8");
63  }
64  else
65  {
66  return stripos($a_haystack, $a_needle, $a_offset);
67  }
68  }
+ Here is the caller graph for this function:

◆ strLen()

◆ strPos()

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

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

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

35  {
36  if (function_exists("mb_strpos"))
37  {
38  return mb_strpos($a_haystack, $a_needle, $a_offset, "UTF-8");
39  }
40  else
41  {
42  return strpos($a_haystack, $a_needle, $a_offset);
43  }
44  }
+ 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 217 of file class.ilStr.php.

References array.

Referenced by ilPageObjectGUI\insertPageToc().

218  {
219  $positions = array();
220  $cpos = 0;
221  while(is_int($pos = strpos($a_haystack, $a_needle, $cpos)))
222  {
223  $positions[] = $pos;
224  $cpos = $pos+1;
225  }
226  return $positions;
227  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ strrPos()

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

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

Referenced by ilPCParagraph\linkTermsInDom().

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

◆ strToLower()

static ilStr::strToLower (   $a_string)
static

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

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

104  {
105  if (function_exists("mb_strtolower"))
106  {
107  return mb_strtolower($a_string, "UTF-8");
108  }
109  else
110  {
111  return strtolower($a_string);
112  }
113  }
+ Here is the caller graph for this function:

◆ strToUpper()

static ilStr::strToUpper (   $a_string)
static

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

References string.

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

116  {
117  $a_string = (string) $a_string;
118  if (function_exists("mb_strtoupper"))
119  {
120  return mb_strtoupper($a_string, "UTF-8");
121  }
122  else
123  {
124  return strtoupper($a_string);
125  }
126  }
Add rich text string
The name of the decorator.
+ 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(), ilPCParagraph\linkTermsInDom(), ilObjForumAccess\prepareMessageForLists(), SurveyTextQuestion\saveUserInput(), ilAssQuestionSkillAssignmentRegistry\setStringifiedImports(), ilUtil\shortenText(), ilUtil\shortenWords(), and ilObjBibliographic\writeSourcefileEntriesToDb().

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

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