forked from phpgearbox/string
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIndexOf.php
More file actions
64 lines (61 loc) · 2.31 KB
/
Copy pathIndexOf.php
File metadata and controls
64 lines (61 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php namespace Gears\String\Methods;
////////////////////////////////////////////////////////////////////////////////
// __________ __ ________ __________
// \______ \ |__ ______ / _____/ ____ _____ ______\______ \ _______ ___
// | ___/ | \\____ \/ \ ____/ __ \\__ \\_ __ \ | _// _ \ \/ /
// | | | Y \ |_> > \_\ \ ___/ / __ \| | \/ | ( <_> > <
// |____| |___| / __/ \______ /\___ >____ /__| |______ /\____/__/\_ \
// \/|__| \/ \/ \/ \/ \/
// -----------------------------------------------------------------------------
// Designed and Developed by Brad Jones <brad @="bjc.id.au" />
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
use voku\helper\UTF8;
trait IndexOf
{
/**
* Returns the index of the first occurrence of $needle in the string,
* and false if not found. Accepts an optional offset from which to begin
* the search.
*
* @param string $needle Substring to look for.
*
* @param int $offset Offset from which to search.
*
* @return int|bool The occurrence's index if found,
* otherwise false.
*/
public function indexOf($needle, $offset = 0)
{
return UTF8::strpos
(
$this->scalarString,
(string)$needle,
(int)$offset,
$this->encoding
);
}
/**
* Returns the index of the last occurrence of $needle in the string,
* and false if not found. Accepts an optional offset from which to begin
* the search. Offsets may be negative to count from the last character
* in the string.
*
* @param string $needle Substring to look for.
*
* @param int $offset Offset from which to search.
*
* @return int|bool The last occurrence's index if found,
* otherwise false.
*/
public function indexOfLast($needle, $offset = 0)
{
return UTF8::strrpos
(
$this->scalarString,
(string)$needle,
(int)$offset,
$this->encoding
);
}
}