1
0
mirror of https://github.com/danielstjules/Stringy.git synced 2025-09-03 01:52:43 +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

@@ -31,6 +31,8 @@ PHP 5.3+ and HHVM. Inspired by underscore.string.js.
* [htmlDecode](#htmldecode)
* [htmlEncode](#htmlencode)
* [humanize](#humanize)
* [indexOf](#indexof)
* [indexOfLast](#indexoflast)
* [insert](#insert)
* [isAlpha](#isalpha)
* [isAlphanumeric](#isalphanumeric)
@@ -475,6 +477,34 @@ S::create('author_id')->humanize();
S::humanize('author_id'); // 'Author'
```
#### indexOf
$stringy->indexOf(string $substr [, $offset = 0 ]);
S::indexOf(string $str , string $substr [, $offset = 0 [, $encoding = null ]])
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.
```php
S::create('string', 'UTF-8')->indexOf('ing');
S::indexOf('string', 'ing', 0, 'UTF-8'); // 3
```
#### indexOfLast
$stringy->indexOfLast(string $substr [, $offset = 0 ]);
S::indexOfLast(string $str , string $substr [, $offset = 0 [, $encoding = null ]])
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.
```php
S::create('string', 'UTF-8')->indexOfLast('ing');
S::indexOfLast('string string', 'ing', 0, 'UTF-8'); // 10
```
#### insert
$stringy->insert(int $index, string $substring)