# [VOTE] Voting opens for str_starts_with and ends_with functions

- Thread: https://externals.io/message/106162
- Original archive: https://news-web.php.net/php.internals/106162
- Started by Andrew Gromov on 2019-07-08T10:15:29+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #106162 — Andrew Gromov — 2019-07-08T10:15:29+00:00

URL: https://externals.io/message/106162#106162

> For those voting against adding these functions, can you clarify why?
> Do you dislike how they are named, or do you not see the need for the
> case insensitive versions, or is there an issue with the implementation?


I believe that star_with/end_with is useful, but not in this form.
The standard library has 98 string functions with different naming styles.
Adding 4 more (8 for mb_) functions for actually two(one?) tasks is redundant.

I think that more discussion is needed.

My preferred variants:

1) One function

```php
str_contains(
    $haystack, 
    $needle, 
    [CASE_INSENSITIVE|FROM_BEGIN|FROM_END|MULTI_BYTE] = 0, 
    [$encoding] = utf8
)
```

2)Or two

```php
str_starts_with(...see above, but without FROM_BEGIN|FROM_END)
str_ends_with(...see above, but without FROM_BEGIN|FROM_END)
```

Best regards,Andrey

---

## #106164 — Marco Pivetta — 2019-07-08T11:30:12+00:00

URL: https://externals.io/message/106162#106164

> > […]
>
>
> I believe that star_with/end_with is useful, but not in this form.
> The standard library has 98 string functions with different naming styles.
> Adding 4 more (8 for mb_) functions for actually two(one?) tasks is
> redundant.
>
> I think that more discussion is needed.
>
> My preferred variants:
>
> 1) One function
>
> ```php
> str_contains(
>     $haystack,
>     $needle,
>     [CASE_INSENSITIVE|FROM_BEGIN|FROM_END|MULTI_BYTE] = 0,
>     [$encoding] = utf8
> )
> ```
>
> 2)Or two
>
> ```php
> str_starts_with(...see above, but without FROM_BEGIN|FROM_END)
> str_ends_with(...see above, but without FROM_BEGIN|FROM_END)
> ```
>
> Best regards,Andrey
>

Please don't switch behaviours via flags: separate names and
implementations are much clearer and much simpler to follow.

Yes, you will have multiple variations, but that's fine.
