1
0
mirror of https://github.com/danielstjules/Stringy.git synced 2025-09-02 01:22:37 +02:00

Merge branch 'indexOf'

This commit is contained in:
Daniel St. Jules
2015-06-29 14:56:25 -07:00
6 changed files with 140 additions and 0 deletions

View File

@@ -421,6 +421,34 @@ class StaticStringy
->containsAll($needles, $caseSensitive);
}
/**
* Returns the offset/index of the first occurance of $substr in the string.
* In case $substr is not a substring of the string, returns false.
*
* @param string $str The haystack to search through
* @param string $substr substring
* @param int $offset
* @return int|bool
*/
public static function indexOf($str, $substr, $offset = 0, $encoding = null)
{
return Stringy::create($str, $encoding)->indexOf($substr, $offset);
}
/**
* Returns the offset/index of the last occurance of $substr in the string.
* In case $substr is not a substring of the string, returns false.
*
* @param string $str The haystack to search through
* @param string $substr substring
* @param int $offset
* @return int|bool
*/
public static function indexOfLast($str, $substr, $offset = 0, $encoding = null)
{
return Stringy::create($str, $encoding)->indexOfLast($substr, $offset);
}
/**
* Surrounds a string with the given substring.
*

View File

@@ -894,6 +894,32 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
return true;
}
/**
* Returns the offset/index of the first occurrence of $substr in the string.
* In case $substr is not a substring of the string, returns false.
*
* @param string $substr substring
* @param int $offset
* @return int|bool
*/
public function indexOf($substr, $offset = 0)
{
return mb_strpos($this->str, (string)$substr, (int)$offset, $this->encoding);
}
/**
* Returns the offset/index of the last occurrence of $substr in the string.
* In case $substr is not a substring of the string, returns false.
*
* @param string $substr substring
* @param int $offset
* @return int|bool
*/
public function indexOfLast($substr, $offset = 0)
{
return mb_strrpos($this->str, (string)$substr, (int)$offset, $this->encoding);
}
/**
* Surrounds $str with the given substring.
*