php--查找字符串出现位置

来源:互联网 发布:php session mysql 编辑:程序博客网 时间:2024/06/07 14:17

strpos---查找字符串出现的位置

Example

        // stripos() - 查找字符串首次出现的位置(不区分大小写)// strrpos() - 查找字符串在目标字符串最后一次出现的位置// strripos() - 查找字符串在目标字符串最后一次出现的位置(不区分大小写)// strstr()  - 查找字符串的首次出现$mystring = 'chang';$findme = 'a';$pos = strpos($mystring, $findme);//int 2// 注意这里使用的是 ===。简单的 == 不能像我们期待那样工作if($pos === false) {echo "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}";}

0 0
原创粉丝点击