php如何获取中文汉字,在某个字段中的位置

[复制链接]
查看11 | 回复2 | 2011-3-20 20:25:39 | 显示全部楼层 |阅读模式
<?php$mystring = '我是中国人我是安徽人我是人';$findme = '我';$pos = strpos($mystring,$findme,0);//0表示是否是第一次出现,0的话就是,1的话就不是//这时候要看中文是什么编码了,是UTF-8的话就是$pos/3,是GBK或GB2312的话就$pos/2,if ($pos === false) {
echo "The string '$findme' was not found in the string '$mystring'";} else {
echo "The string '$findme' was found in the s
回复

使用道具 举报

千问 | 2011-3-20 20:25:39 | 显示全部楼层
mb_strpos()函数,需要PHP5支持
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行