ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
ilStr Class Reference

Multi byte sensitive string functions. More...

+ Collaboration diagram for ilStr:

Public Member Functions

 strPos ($a_haystack, $a_needle, $a_offset=NULL)
 
 strToUpper ($a_string)
 
 strCmp ($a, $b)
 Compare two strings. More...
 
 isUtf8 ($a_str)
 Check whether string is utf-8. More...
 
 replaceFirsOccurence ($a_old, $a_new, $a_str)
 Replaces the first occurence of $a_old in $a_str with $a_new. More...
 

Static Public Member Functions

static subStr ($a_str, $a_start, $a_length=NULL)
 
static strLen ($a_string)
 
static strToLower ($a_string)
 
static shortenText ($a_string, $a_start_pos, $a_num_bytes, $a_encoding='UTF-8')
 Shorten text to the given number of bytes. More...
 
static strPosAll ($a_haystack, $a_needle)
 Get all positions of a 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 32 of file class.ilStr.php.

Member Function Documentation

◆ isUtf8()

ilStr::isUtf8 (   $a_str)

Check whether string is utf-8.

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

Referenced by ilObjLanguage\check().

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

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

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

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

Referenced by ilPageObjectGUI\insertPageToc().

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

Referenced by ilDBGenerator\shortenText().

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

◆ strCmp()

ilStr::strCmp (   $a,
  $b 
)

Compare two strings.

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

References strToUpper().

Referenced by ilUtil\sort_func().

120  {
121  global $ilCollator;
122 
123  if (is_object($ilCollator))
124  {
125  return ($ilCollator->compare(ilStr::strToUpper($a), ilStr::strToUpper($b)) > 0);
126  }
127  else
128  {
129  return (strcoll(ilStr::strToUpper($a), ilStr::strToUpper($b)) > 0);
130  }
131  }
strToUpper($a_string)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ strLen()

static ilStr::strLen (   $a_string)
static

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

Referenced by ilObjQuestionPool\_getFullPathToQpl(), ilICalWriter\addLine(), ilDataCollectionField\checkValidity(), ilUtil\isPassword(), ilObjForumAccess\prepareMessageForLists(), assTextQuestion\saveWorkingData(), ilUtil\shortenText(), and ilUtil\shortenWords().

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

◆ strPos()

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

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

Referenced by ilMailForm\getRecipientAsync(), assTextQuestion\isKeywordMatching(), ilUtil\shortenText(), and assOrderingHorizontal\splitAndTrimOrderElementText().

47  {
48  if (function_exists("mb_strpos"))
49  {
50  return mb_strpos($a_haystack, $a_needle, $a_offset, "UTF-8");
51  }
52  else
53  {
54  return strpos($a_haystack, $a_needle, $a_offset);
55  }
56  }
+ 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 201 of file class.ilStr.php.

Referenced by ilPageObjectGUI\insertPageToc().

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

◆ strToLower()

static ilStr::strToLower (   $a_string)
static

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

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

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

◆ strToUpper()

ilStr::strToUpper (   $a_string)

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

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

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

◆ subStr()

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

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

Referenced by ilObjQuestionPool\_getFullPathToQpl(), ilSCORMCertificateAdapter\addAdditionalFormElements(), ilICalWriter\addLine(), ilObjForumAccess\prepareMessageForLists(), assTextQuestion\saveWorkingData(), ilUtil\shortenText(), and ilUtil\shortenWords().

35  {
36  if (function_exists("mb_substr"))
37  {
38  return mb_substr($a_str, $a_start, $a_length, "UTF-8");
39  }
40  else
41  {
42  return substr($a_str, $a_start, $a_length);
43  }
44  }
+ Here is the caller graph for this function:

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