Conversation
There was a problem hiding this comment.
I'm in favor, but this will need an RFC (https://wiki.php.net/rfc/howto).
163c576 to
0de0e3d
Compare
0de0e3d to
5994551
Compare
This sounds great. I will go ahead and create an RFC for this. |
|
To avoid another PR/RFC, what do you think in including a |
See https://externals.io/message/108562 as to why it doesn't make a lot of sense to include a case insensitive version. |
|
I am not sure what is the difference between this and if (strpos === false). |
|
To me, as a user, it is purely about UX. Having a |
|
Could you please add a test covering the examples you have in the RFC? That would be quite good to ensure that things behave properly throughout time 👍 |
Tests have been added. |
|
what about multibyte support? // UTF-8
str_contains("тест", "т"); // ???
|
That would return |
|
@Girgias maybe add third option for case-insensitive cases? or make new function |
... Have you read this PR thread and or the RFC? I've linked reasons as to why it doesn't make sense: #5179 (comment) |
1 similar comment
... Have you read this PR thread and or the RFC? I've linked reasons as to why it doesn't make sense: #5179 (comment) |
No. But now yes. There are answers to all my questions. Thanks. |
|
The RFC has been accepted and the voting phase has been closed. |
|
Are there official polyfills for the new this and the other new string functions? |
|
@Gemorroj perfect, thank you |
Repurposing strpos and strstr for this use-case has a few down sides. Either, they are: not very intuitive for a reader |
Empty string management differs. When I search something I don't want always to have true returned in some cases. I think it is bug-compliant. |
* RemoveUnusedVariableInCatchRector (https://wiki.php.net/rfc/non-capturing_catches) * ClassPropertyAssignToConstructorPromotionRector (https://wiki.php.net/rfc/constructor_promotion php/php-src#5291) * StrContainsRector (https://externals.io/message/108562 php/php-src#5179)
|
I always wanted this, Since the day i started programming in PHP :) . Thanks Finally |
Applied rules: * TokenGetAllToObjectRector (https://wiki.php.net/rfc/token_as_object) * StrEndsWithRector (https://wiki.php.net/rfc/add_str_starts_with_and_ends_with_functions) * StrStartsWithRector (https://wiki.php.net/rfc/add_str_starts_with_and_ends_with_functions) * StrContainsRector (https://externals.io/message/108562 php/php-src#5179)
Applied rules: * StrEndsWithRector (https://wiki.php.net/rfc/add_str_starts_with_and_ends_with_functions) * StrStartsWithRector (https://wiki.php.net/rfc/add_str_starts_with_and_ends_with_functions) * StrContainsRector (https://externals.io/message/108562 php/php-src#5179)
Applied rules: * ClassPropertyAssignToConstructorPromotionRector (https://wiki.php.net/rfc/constructor_promotion php/php-src#5291) * StrStartsWithRector (https://wiki.php.net/rfc/add_str_starts_with_and_ends_with_functions) * StrContainsRector (https://externals.io/message/108562 php/php-src#5179) * ReadOnlyPropertyRector (https://wiki.php.net/rfc/readonly_properties_v2)
Applied rules: * LongArrayToShortArrayRector * TernaryToNullCoalescingRector * PublicConstantVisibilityRector (https://wiki.php.net/rfc/class_const_visibility) * ListToArrayDestructRector (https://wiki.php.net/rfc/short_list_syntax https://www.php.net/manual/en/migration71.new-features.php#migration71.new-features.symmetric-array-destructuring) * MixedTypeRector * StrContainsRector (https://externals.io/message/108562 php/php-src#5179) * ChangeSwitchToMatchRector (https://wiki.php.net/rfc/match_expression_v2) * FinalizePublicClassConstantRector (https://php.watch/versions/8.1/final-class-const) * NullToStrictStringFuncCallArgRector * TypedPropertyFromAssignsRector
There is currently no function to check if a string contains another string. The only way to achive this behavior is to use other functions like
strposorstrstr.This type of function exists for example for arrays (
in_array), while there is stillarray_search(equivalent tostrpos) available.I would like to propose the new function
str_contains:It takes a $haystack and $needle as a parameter and checks if the $haystack string contains the $needle string. It returns a boolean value (
true/false) to indicate weather the $needle is found.Example: