strstr() 查找字符串的首次出现 。每日分享PHP知识点,大家都赞同关注是一种动力,分享是一种美德,再说了关注分享一下又不会怀孕?只要你开心就好......
string strstr ( string $haystack , mixed $needle [, bool $before_needle = false ] )
说明:返回 haystack 字符串从 needle 第一次出现的位置开始到 haystack 结尾的字符串。
Note:
该函数区分大小写。如果想要不区分大小写,请使用 stristr()。Note:
如果你仅仅想确定 needle 是否存在于 haystack 中,请使用速度更快、耗费内存更少的 strpos() 函数 参数描述haystack
输入字符串。needle
如果 needle 不是一个字符串,那么它将被转化为整型并且作为字符的序号来使用。before_needle
若为 TRUE,strstr() 将返回 needle 在 haystack 中的位置之前的部分。 返回值:返回字符串的一部分或者 FALSE(如果未发现 needle)。 实例1:<?php $email = 'name@example.com';$domain = strstr($email, '@');echo $domain; // 打印 @example.com$user = strstr($email, '@', true); // 从 PHP 5.3.0 起echo $user; // 打印 name?>
实例2:
<?php echo strstr("Hello world!","world"); // 输出 world!?>
![0c3af99666299453ac6ee1c6b0fc8df1.png](https://img-blog.csdnimg.cn/img_convert/0c3af99666299453ac6ee1c6b0fc8df1.png)
![763f5a03b03de80e123a676190690b26.png](https://img-blog.csdnimg.cn/img_convert/763f5a03b03de80e123a676190690b26.png)