定义

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,不包含@
?>

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-10
  • 2021-10-19
  • 2022-12-23
  • 2022-12-23
  • 2021-11-17
  • 2021-11-26
猜你喜欢
  • 2022-12-23
  • 2021-08-12
  • 2021-10-03
  • 2022-02-22
  • 2022-12-23
  • 2021-12-06
  • 2021-08-06
相关资源
相似解决方案