(PHP 4, PHP 5, PHP 7)
strstr — Find the first occurrence of a string
$haystack
, string $needle
, bool $before_needle
= false
) : string|false
Returns part of haystack
string starting from and including the first
occurrence of needle
to the end of
haystack
.
Notă:
This function is case-sensitive. For case-insensitive searches, use stristr().
Notă:
If you only want to determine if a particular
needle
occurs withinhaystack
, use the faster and less memory intensive function strpos() instead.
haystack
The input string.
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
, strstr() returns
the part of the haystack
before the first
occurrence of the needle
(excluding the needle).
Returns the portion of string, or false
if needle
is not found.
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 strstr() example
<?php
$email = 'name@example.com';
$domain = strstr($email, '@');
echo $domain; // prints @example.com
$user = strstr($email, '@', true); // As of PHP 5.3.0
echo $user; // prints name
?>