ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups 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.
 isUtf8 ($a_str)
 Check whether string is utf-8.
 replaceFirsOccurence ($a_old, $a_new, $a_str)
 Replaces the first occurence of $a_old in $a_str with $a_new.

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.
static strPosAll ($a_haystack, $a_needle)
 Get all positions of a string.

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:
class.ilStr.php 29301 2011-05-27 09:20:28Z smeyer

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

Member Function Documentation

ilStr::isUtf8 (   $a_str)

Check whether string is utf-8.

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

Referenced by ilObjLanguage\check().

{
if (function_exists("mb_detect_encoding"))
{
if (mb_detect_encoding($a_str, "UTF-8") == "UTF-8")
{
return true;
}
}
else
{
// copied from http://www.php.net/manual/en/function.mb-detect-encoding.php
$c=0; $b=0;
$bits=0;
$len=strlen($str);
for($i=0; $i<$len; $i++){
$c=ord($str[$i]);
if($c > 128){
if(($c >= 254)) return false;
elseif($c >= 252) $bits=6;
elseif($c >= 248) $bits=5;
elseif($c >= 240) $bits=4;
elseif($c >= 224) $bits=3;
elseif($c >= 192) $bits=2;
else return false;
if(($i+$bits) > $len) return false;
while($bits > 1){
$i++;
$b=ord($str[$i]);
if($b < 128 || $b > 191) return false;
$bits--;
}
}
}
return true;
}
return false;
}

+ Here is the caller graph for this function:

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().

{
if (is_int(strpos($a_str, $a_old)))
{
$a_str = substr_replace ($a_str, $a_new, strpos($a_str, $a_old), strlen($a_old));
}
return $a_str;
}

+ Here is the caller graph for this function:

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.

{
return mb_strcut($a_string, $a_start_pos, $a_num_bytes, $a_encoding);
}
ilStr::strCmp (   $a,
  $b 
)

Compare two strings.

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

References strToUpper().

Referenced by ilUtil\sort_func().

{
global $ilCollator;
if (is_object($ilCollator))
{
return ($ilCollator->compare(ilStr::strToUpper($a), ilStr::strToUpper($b)) > 0);
}
else
{
return (strcoll(ilStr::strToUpper($a), ilStr::strToUpper($b)) > 0);
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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().

{
if (function_exists("mb_strlen"))
{
return mb_strlen($a_string, "UTF-8");
}
else
{
return strlen($a_string);
}
}

+ Here is the caller graph for this function:

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().

{
if (function_exists("mb_strpos"))
{
return mb_strpos($a_haystack, $a_needle, $a_offset, "UTF-8");
}
else
{
return strpos($a_haystack, $a_needle, $a_offset);
}
}

+ Here is the caller graph for this function:

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().

{
$positions = array();
$cpos = 0;
while(is_int($pos = strpos($a_haystack, $a_needle, $cpos)))
{
$positions[] = $pos;
$cpos = $pos+1;
}
return $positions;
}

+ Here is the caller graph for this function:

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().

{
if (function_exists("mb_strtolower"))
{
return mb_strtolower($a_string, "UTF-8");
}
else
{
return strtolower($a_string);
}
}

+ Here is the caller graph for this function:

ilStr::strToUpper (   $a_string)

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

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

{
$a_string = (string) $a_string;
if (function_exists("mb_strtoupper"))
{
return mb_strtoupper($a_string, "UTF-8");
}
else
{
return strtoupper($a_string);
}
}

+ Here is the caller graph for this function:

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().

{
if (function_exists("mb_substr"))
{
return mb_substr($a_str, $a_start, $a_length, "UTF-8");
}
else
{
return substr($a_str, $a_start, $a_length);
}
}

+ Here is the caller graph for this function:


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