记忆力越来越差了,PHP有这么多函数怎么办啊!!!
1.strstr
说明
返回 haystack
字符串从 needle
第一次出现的位置开始到 haystack
结尾的字符串。
Note:
该函数区分大小写。如果想要不区分大小写,请使用 stristr()。
Note:
如果你仅仅想确定
needle
是否存在于haystack
中,请使用速度更快、耗费内存更少的 strpos()函数。
范例
Example #1 strstr() 范例
<?php $email = '[email protected]'; $domain = strstr($email, '@'); echo $domain; // 打印 @example.com $user = strstr($email, '@', true); // 从 PHP 5.3.0 起 echo $user; // 打印 name ?>
2.strpos
说明
返回 needle
在 haystack
中首次出现的数字位置。
Example #3 使用位置偏移量
<?php // 忽视位置偏移量之前的字符进行查找 $newstring = 'abcdef abcdef'; $pos = strpos($newstring, 'a', 1); // $pos = 7, 不是 0 ?>
stristr
(PHP 4, PHP 5, PHP 7)
stristr — strstr() 函数的忽略大小写版本
范例
Example #1 stristr() 范例
<?php $email = '[email protected]'; echo stristr($email, 'e'); // 输出 [email protected] echo stristr($email, 'e', true); // 自 PHP 5.3.0 起,输出 US ?>
第三方