PluginProbe
wpDataTables – WordPress Data Table, Dynamic Tables & Table Charts Plugin / 6.5.1.7
wpDataTables – WordPress Data Table, Dynamic Tables & Table Charts Plugin v6.5.1.7
6.5.1.7 6.5.1.6 6.5.1.5 6.5.1.4 6.5.1.3 6.5.1.2 6.5.1.1 6.5.0.9 6.5.0.8 6.5.0.7 6.5.0.6 trunk 3.4.2.40 3.4.2.41 3.4.2.42 3.4.2.43 3.4.2.44 3.4.2.45 3.4.2.46 3.4.2.47 3.4.2.48 3.4.2.49 3.4.2.50 6.3.2 6.3.3.1 All 47 releases
wpdatatables / lib / phpoffice / phpspreadsheet / src / PhpSpreadsheet / Calculation / TextData / Search.php

Search.php in wpDataTables – WordPress Data Table, Dynamic Tables & Table Charts Plugin 6.5.1.7, at lib/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/TextData/Search.php

98 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace PhpOffice\PhpSpreadsheet\Calculation\TextData;
4
5 use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
6 use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
7 use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
8 use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
9
10 class Search
11 {
12 use ArrayEnabled;
13
14 /**
15 * FIND (case sensitive search).
16 *
17 * @param mixed $needle The string to look for
18 * Or can be an array of values
19 * @param mixed $haystack The string in which to look
20 * Or can be an array of values
21 * @param mixed $offset Integer offset within $haystack to start searching from
22 * Or can be an array of values
23 *
24 * @return array|int|string The offset where the first occurrence of needle was found in the haystack
25 * If an array of values is passed for the $value or $chars arguments, then the returned result
26 * will also be an array with matching dimensions
27 */
28 public static function sensitive($needle, $haystack, $offset = 1)
29 {
30 if (is_array($needle) || is_array($haystack) || is_array($offset)) {
31 return self::evaluateArrayArguments([self::class, __FUNCTION__], $needle, $haystack, $offset);
32 }
33
34 try {
35 $needle = Helpers::extractString($needle);
36 $haystack = Helpers::extractString($haystack);
37 $offset = Helpers::extractInt($offset, 1, 0, true);
38 } catch (CalcExp $e) {
39 return $e->getMessage();
40 }
41
42 if (StringHelper::countCharacters($haystack) >= $offset) {
43 if (StringHelper::countCharacters($needle) === 0) {
44 return $offset;
45 }
46
47 $pos = mb_strpos($haystack, $needle, --$offset, 'UTF-8');
48 if ($pos !== false) {
49 return ++$pos;
50 }
51 }
52
53 return ExcelError::VALUE();
54 }
55
56 /**
57 * SEARCH (case insensitive search).
58 *
59 * @param mixed $needle The string to look for
60 * Or can be an array of values
61 * @param mixed $haystack The string in which to look
62 * Or can be an array of values
63 * @param mixed $offset Integer offset within $haystack to start searching from
64 * Or can be an array of values
65 *
66 * @return array|int|string The offset where the first occurrence of needle was found in the haystack
67 * If an array of values is passed for the $value or $chars arguments, then the returned result
68 * will also be an array with matching dimensions
69 */
70 public static function insensitive($needle, $haystack, $offset = 1)
71 {
72 if (is_array($needle) || is_array($haystack) || is_array($offset)) {
73 return self::evaluateArrayArguments([self::class, __FUNCTION__], $needle, $haystack, $offset);
74 }
75
76 try {
77 $needle = Helpers::extractString($needle);
78 $haystack = Helpers::extractString($haystack);
79 $offset = Helpers::extractInt($offset, 1, 0, true);
80 } catch (CalcExp $e) {
81 return $e->getMessage();
82 }
83
84 if (StringHelper::countCharacters($haystack) >= $offset) {
85 if (StringHelper::countCharacters($needle) === 0) {
86 return $offset;
87 }
88
89 $pos = mb_stripos($haystack, $needle, --$offset, 'UTF-8');
90 if ($pos !== false) {
91 return ++$pos;
92 }
93 }
94
95 return ExcelError::VALUE();
96 }
97 }
98