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.


str_contains($aString, $aSubstring)
  • $aString: The string to be searched.
  • $aSubstring: The substring to be found.


The following example demonstrates the case sensitive nature of str_contains().

$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.

All contributors

Looking to contribute?

Learn PHP on Codecademy