无为清净楼资源网 Design By www.qnjia.com

本文实例讲述了php通过strpos查找字符串出现位置的方法。分享给大家供大家参考。具体分析如下:

strpos用来查找一个字符串在另一个字符串中首次出现的位置,strpos区分大小写,如果没有找到则返回false,所以strpos有两种类型的返回值,一种是整形,一种是bool型,开发过程中需要注意

<"Hello world!","wo");
"htmlcode">
<"needle23423432";
$pos = strpos($haystack, "needle");
if ($pos==false) {
 print("Not found based (==) test\n");
} else {
 print("Found based (==) test\n");
}
if ($pos===false) {
 print("Not found based (===) test\n");
} else {
 print("Found based (===) test\n");
}
"htmlcode">
This script will print:
 
Not found based (==) test
Found based (===) test
 
The (===) test is correct.

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

标签:
php,strpos,查找,字符串,出现位置,方法

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