相思资源网 Design By www.200059.com

本文实例讲述了php常用字符串查找函数strstr()与strpos()。分享给大家供大家参考,具体如下:

一句话使用strpos判断 ===!==,这样才能达到预期的效果,性能要比strstr要好,只是判断是否包含某个字符串就用这个了。

string strstr ( string $haystack , mixed $needle [, bool $before_needle = false ] )

1、$haystack被查找的字符串,$needle要查找的内容
2、如查找到则返回字符串的一部分,如没找到则返回FALSE
3、该函数区分大小写,如果想要不区分大小写,请使用 stristr()
4、如果你仅仅想确定needle是否存在于haystack中请使用速度更快、耗费内存更少的strpos()函数

<"color: #0000ff">mixed strpos ( string $haystack , mixed $needle [, int $offset = 0 ] )

1、$haystack被查找的字符串,$needle要查找的内容
2、返回 needle 在 haystack 中首次出现的数字位置
3、该函数区分大小写,如果想要不区分大小写,请使用 stripos()
4、返回值,如找到的话,返回needle 存在于 haystack 字符串起始的位置(注意字符串位置是从0开始,而不是从1开始),没找到则返回FALSE,但也可能返回等同于 FALSE 的非布尔值

<"htmlcode">
<"The string '$findme' was not found in the string '$mystring'";
} else {
  echo "The string '$findme' was found in the string '$mystring'";
  echo " and exists at position $pos";
}
"htmlcode">
<"The string '$findme' was found in the string '$mystring'";
     echo " and exists at position $pos";
} else {
   echo "The string '$findme' was not found in the string '$mystring'";
}
"htmlcode">
<"_blank" href="//www.jb51.net/Special/168.htm">php常用函数与技巧总结》、《php字符串(string)用法总结》、《PHP数组(Array)操作技巧大全》、《PHP基本语法入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家PHP程序设计有所帮助。

标签:
php,字符串查找函数,strstr(),strpos()

相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com

评论“php常用字符串查找函数strstr()与strpos()实例分析”

暂无php常用字符串查找函数strstr()与strpos()实例分析的评论...