ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Search.php
Go to the documentation of this file.
1 <?php
2 
4 
8 
9 class Search
10 {
20  public static function sensitive($needle, $haystack, $offset = 1)
21  {
22  $needle = Functions::flattenSingleValue($needle);
23  $haystack = Functions::flattenSingleValue($haystack);
24  $offset = Functions::flattenSingleValue($offset);
25 
26  if (!is_bool($needle)) {
27  if (is_bool($haystack)) {
28  $haystack = ($haystack) ? Calculation::getTRUE() : Calculation::getFALSE();
29  }
30 
31  if (($offset > 0) && (StringHelper::countCharacters($haystack) > $offset)) {
32  if (StringHelper::countCharacters($needle) === 0) {
33  return $offset;
34  }
35 
36  $pos = mb_strpos($haystack, $needle, --$offset, 'UTF-8');
37  if ($pos !== false) {
38  return ++$pos;
39  }
40  }
41  }
42 
43  return Functions::VALUE();
44  }
45 
55  public static function insensitive($needle, $haystack, $offset = 1)
56  {
57  $needle = Functions::flattenSingleValue($needle);
58  $haystack = Functions::flattenSingleValue($haystack);
59  $offset = Functions::flattenSingleValue($offset);
60 
61  if (!is_bool($needle)) {
62  if (is_bool($haystack)) {
63  $haystack = ($haystack) ? Calculation::getTRUE() : Calculation::getFALSE();
64  }
65 
66  if (($offset > 0) && (StringHelper::countCharacters($haystack) > $offset)) {
67  if (StringHelper::countCharacters($needle) === 0) {
68  return $offset;
69  }
70 
71  $pos = mb_stripos($haystack, $needle, --$offset, 'UTF-8');
72  if ($pos !== false) {
73  return ++$pos;
74  }
75  }
76  }
77 
78  return Functions::VALUE();
79  }
80 }
static insensitive($needle, $haystack, $offset=1)
SEARCHINSENSITIVE.
Definition: Search.php:55
static countCharacters($value, $enc='UTF-8')
Get character count.
static getFALSE()
Return the locale-specific translation of FALSE.
static getTRUE()
Return the locale-specific translation of TRUE.
static sensitive($needle, $haystack, $offset=1)
SEARCHSENSITIVE.
Definition: Search.php:20
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.
Definition: Functions.php:649