ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
All Data Structures Namespaces Files Functions Variables Modules Pages
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 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...
 

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

◆ isUtf8()

static ilStr::isUtf8 (   $a_str)
static

Check whether string is utf-8.

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

Referenced by ilObjLanguage\check(), ilDataCollectionRecordListGUI\getImportFieldsFromTitles(), and ilDataCollectionRecordListGUI\importRecords().

153  {
154  if (function_exists("mb_detect_encoding"))
155  {
156  if (mb_detect_encoding($a_str, "UTF-8", true) == "UTF-8")
157  {
158  return true;
159  }
160  }
161  else
162  {
163  // copied from http://www.php.net/manual/en/function.mb-detect-encoding.php
164  $c=0; $b=0;
165  $bits=0;
166  $len=strlen($str);
167  for($i=0; $i<$len; $i++){
168  $c=ord($str[$i]);
169  if($c > 128){
170  if(($c >= 254)) return false;
171  elseif($c >= 252) $bits=6;
172  elseif($c >= 248) $bits=5;
173  elseif($c >= 240) $bits=4;
174  elseif($c >= 224) $bits=3;
175  elseif($c >= 192) $bits=2;
176  else return false;
177  if(($i+$bits) > $len) return false;
178  while($bits > 1){
179  $i++;
180  $b=ord($str[$i]);
181  if($b < 128 || $b > 191) return false;
182  $bits--;
183  }
184  }
185  }
186  return true;
187  }
188  return false;
189  }
if(!file_exists(getcwd().'/ilias.ini.php')) if(isset( $_GET["client_id"]))
registration confirmation script for ilias
Definition: confirmReg.php:20
while(!file_exists( 'ilias.ini.php'))
Definition: latex.php:4
if( $out) else
+ 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 214 of file class.ilStr.php.

Referenced by ilPageObjectGUI\insertPageToc().

215  {
216  if (is_int(strpos($a_str, $a_old)))
217  {
218  $a_str = substr_replace ($a_str, $a_new, strpos($a_str, $a_old), strlen($a_old));
219  }
220  return $a_str;
221  }
+ 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 144 of file class.ilStr.php.

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

145  {
146  return mb_strcut($a_string, $a_start_pos, $a_num_bytes, $a_encoding);
147  }
+ Here is the caller graph for this function:

◆ strCmp()

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

Compare two strings.

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

References strToUpper().

Referenced by ilUtil\sort_func().

118  {
119  global $ilCollator;
120 
121  if (is_object($ilCollator))
122  {
123  return ($ilCollator->compare(ilStr::strToUpper($a), ilStr::strToUpper($b)) > 0);
124  }
125  else
126  {
127  return (strcoll(ilStr::strToUpper($a), ilStr::strToUpper($b)) > 0);
128  }
129  }
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 44 of file class.ilStr.php.

Referenced by ilPCParagraph\linkTermsInDom().

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

◆ strLen()

static ilStr::strLen (   $a_string)
static

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

Referenced by ilObjQuestionPool\_getFullPathToQpl(), ilICalWriter\addLine(), ilWikiPage\afterUpdate(), ilDataCollectionField\checkValidity(), assTextQuestion\getSolutionSubmit(), ilUtil\isPassword(), ilPCParagraph\linkTermsInDom(), ilObjForumAccess\prepareMessageForLists(), ilUtil\shortenText(), ilUtil\shortenWords(), and ilObjBibliographic\writeSourcefileEntriesToDb().

78  {
79  if (function_exists("mb_strlen"))
80  {
81  return mb_strlen($a_string, "UTF-8");
82  }
83  else
84  {
85  return strlen($a_string);
86  }
87  }
+ Here is the caller graph for this function:

◆ strPos()

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

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

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

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

Referenced by ilPageObjectGUI\insertPageToc().

200  {
201  $positions = array();
202  $cpos = 0;
203  while(is_int($pos = strpos($a_haystack, $a_needle, $cpos)))
204  {
205  $positions[] = $pos;
206  $cpos = $pos+1;
207  }
208  return $positions;
209  }
+ Here is the caller graph for this function:

◆ strToLower()

static ilStr::strToLower (   $a_string)
static

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

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

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

◆ strToUpper()

static ilStr::strToUpper (   $a_string)
static

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

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

102  {
103  $a_string = (string) $a_string;
104  if (function_exists("mb_strtoupper"))
105  {
106  return mb_strtoupper($a_string, "UTF-8");
107  }
108  else
109  {
110  return strtoupper($a_string);
111  }
112  }
+ 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(), assTextQuestion\getSolutionSubmit(), ilPCParagraph\linkTermsInDom(), ilObjForumAccess\prepareMessageForLists(), ilUtil\shortenText(), ilUtil\shortenWords(), and ilObjBibliographic\writeSourcefileEntriesToDb().

16  {
17  if (function_exists("mb_substr"))
18  {
19  // see https://bugs.php.net/bug.php?id=62703
20  if ($a_length === NULL)
21  {
22  $a_length = self::strLen($a_str);
23  }
24  return mb_substr($a_str, $a_start, $a_length, "UTF-8");
25  }
26  else
27  {
28  return substr($a_str, $a_start, $a_length);
29  }
30  }
+ Here is the caller graph for this function:

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