Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

str_contains

Description

The str_contains of String for PHP determine if a string contains a given substring.

Syntax

str_contains(string $haystack, string $needle): bool

Parameters

haystack

The string to search in.

needle

The substring to search for in the haystack.

Return

Returns true if needle is in haystack, false otherwise.

Examples

1

<?

$haystack = "haystack needle haystack";
$needle = "needle";

$return = str_contains($haystack, $needle);

var_export($return);

?>
true

2

<?

$haystack = "haystack";
$needle = "needle";

$return = str_contains($haystack, $needle);

var_export($return);

?>
false

3

<?

$haystack = "empty needle returns true";
$needle = "";

$return = str_contains($haystack, $needle);

var_export($return);

?>
true

4

<?

$haystack = "case Case CASE";
$needle1 = "case";
$needle2 = "Case";
$needle3 = "CASE";

$return1 = str_contains($haystack, $needle1);
$return2 = str_contains($haystack, $needle2);
$return3 = str_contains($haystack, $needle3);

var_export($return1);
var_export($return2);
var_export($return3);

?>
truetruetrue
HomeMenu