$haystack
, string $needle
, bool $before_needle
= false
) : string|false
Returns all of haystack
starting from and including the first
occurrence of needle
to the end.
haystack
The string to search in
needle
Dacă needle
nu este un șir de caractere, el este
transformat în întreg și aplicat ca valoarea ordinală a caracterului.
Acest comportament este învechit începând cu PHP 7.3.0 și utilizarea lui este
foarte nerecomandată. În dependență de comportamentul dorit
needle
trebuie transformat în mod explicit în șir de
caractere, sau trebuie efectuat un apel explicit către chr().
before_needle
If true
, stristr()
returns the part of the haystack
before the
first occurrence of the needle
(excluding needle).
needle
and haystack
are examined in a case-insensitive manner.
Returns the matched substring. If needle
is not
found, returns false
.
Versiune | Descriere |
---|---|
8.0.0 |
Passing an int as needle is no longer supported.
|
7.3.0 |
Passing an int as needle has been deprecated.
|
Example #1 stristr() example
<?php
$email = 'USER@EXAMPLE.com';
echo stristr($email, 'e'); // outputs ER@EXAMPLE.com
echo stristr($email, 'e', true); // As of PHP 5.3.0, outputs US
?>
Example #2 Testing if a string is found or not
<?php
$string = 'Hello World!';
if(stristr($string, 'earth') === FALSE) {
echo '"earth" not found in string';
}
// outputs: "earth" not found in string
?>
Example #3 Using a non "string" needle
<?php
$string = 'APPLE';
echo stristr($string, 97); // 97 = lowercase a
// outputs: APPLE
?>
Notă: Această funcție acceptă și date binare.