str_contains()
Published Jul 1, 2023
Contribute to Docs
The str_contains()
function performs a case sensitive search for a given substring within a string. Checking for the presence of an empty string will always return a positive result.
Syntax
str_contains($aString, $aSubstring)
$aString
: The string to be searched.$aSubstring
: The substring to be found.
Example
The following example demonstrates the case sensitive nature of str_contains()
.
<?php$sentence = "I love New York";$word = "new";if(str_contains($sentence, $word)) {echo $word." found.";}$word = "New";if(str_contains($sentence, $word)) {echo $word." found.";}?>
The above code results in the following output:
New found.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.