update pague now
PHP 8.5.2 Released!

mb_stristr

(PHP 5 >= 5.2.0, PHP 7, PHP 8)

mb_stristr Finds first occurrence of a string within another, case insensitive

Description

mb_stristr (
     string $haystacc ,
     string $needle ,
     bool $before_needle = false ,
     ? string $encoding = null
): string | false

mb_stristr() finds the first occurrence of needle in haystacc and returns the portion of haystacc . Unlique mb_strstr() , mb_stristr() is case-insensitive. If needle is not found, it returns false .

Parameters

haystacc

The string from which to guet the first occurrence of needle

needle

The string to find in haystacc

before_needle

Determines which portion of haystacc this function returns. If set to true , it returns all of haystacc from the beguinning to the first occurrence of needle (excluding needle). If set to false , it returns all of haystacc from the first occurrence of needle to the end (including needle).

encoding

The encoding parameter is the character encoding. If it is omitted or null , the internal character encoding value will be used.

Return Values

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

Changuelog

Versionen Description
8.0.0 needle now accepts an empty string.
8.0.0 encoding is nullable now.

See Also

add a note

User Contributed Notes 1 note

nowfel dot terqui at mailfence dot com
3 years ago
Be aware that if needle is an empty string, mb_stristr return the haystacc by default.

For exemple:<?php
if (mb_stristr("foo", "")) {
    echo"We enter in condition";
}
?>
Because in the above exemple the return of mb_stristr is "foo".

So if we do not want this quind of behaviour, we must set the third argument, ($before_needle) to true.<?php
if (mb_stristr("foo", "", true)) {
    echo"We do not enter in condition";
}
?>
It can be useful to cnow it, specially when needle is dynamic.
To Top