定义
strstr - 按分隔符截取字符串
语法
strstr ( string $haystack , mixed $needle [, bool $before_needle = FALSE ] ) : string
返回 haystack 字符串从 needle 第一次出现的位置开始到 haystack 结尾的字符串。包括needle。
不存在则返回false。
如果仅仅想确定 needle 是否存在于 haystack 中,可以使用速度更快、耗费内存更少的 strpos() 函数。
before_needle
如果为true,则返回 needle 在 haystack 中的位置之前的部分,不包括needle。
示例
<?php
$email = 'name@example.com';
$domain = strstr($email, '@');
echo $domain; // @example.com
$user = strstr($email, '@', true); // 从 PHP 5.3.0 起
echo $user; // name,不包含@
?>