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

strstr

Description

The strstr of String for PHP find the first occurrence of a string.

Syntax

strstr(
    string $haystack,
    string $needle,
    bool $before_needle = false
): string|false

Parameters

haystack

The string to search in.

needle

The string to search for.

before_needle

If true, strstr() returns the part of the haystack before the first occurrence of the needle (excluding the needle).

Return

Returns the portion of string, or false if needle is not found.

Examples

1 · haystack needle

<?

$haystack = 'CASEcase';
$needle = 's';

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

echo $return;
se

2 · before_needle

<?

$haystack = 'CASEcase';
$needle = 's';
$before_needle = true;

$return = strstr($haystack, $needle, $before_needle);

echo $return;
CASEca