ILIAS  eassessment Revision 61809
 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

 subStr ($a_str, $a_start, $a_length=NULL)
 strPos ($a_haystack, $a_needle, $a_offset=NULL)
 strLen ($a_string)
 strToUpper ($a_string)
 strCmp ($a, $b)
 Compare two strings.
 isUtf8 ($a_str)
 Check whether string is utf-8.

Static Public Member Functions

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.

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 28404 2011-04-07 05:44:49Z hschottm

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:

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:

ilStr::strLen (   $a_string)

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

Referenced by ilObjQuestionPool\_getFullPathToQpl(), ilObjQuestionPoolGUI\deleteExportFileObject(), 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 assOrderingHorizontal\getOrderingElements(), ilMailForm\getRecipientAsync(), assTextQuestion\isKeywordMatching(), and ilUtil\shortenText().

{
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::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:

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

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

Referenced by ilObjQuestionPool\_getFullPathToQpl(), ilSCORMCertificateAdapter\addAdditionalFormElements(), ilObjQuestionPoolGUI\deleteExportFileObject(), 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: