mb_strpos vs strpos,有什么区别? [英] mb_strpos vs strpos, what's the difference?

查看:101
本文介绍了mb_strpos vs strpos,有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是:我知道.使用多字节char时,应使用mb_ *函数.但是,当我们使用strpos时? 让我们看一下这段代码(保存在utf-8中)

Yes: I know. We should use mb_* function when we're working with multibyte char. But when we're using strpos? Let's take a look this code (saved in utf-8)

var_dump(strpos("My symbol utf-8 is the €.", "\xE2\x82\xAC")); // int(23)

使用mb_strpos有区别吗?难道这项工作不一样吗?毕竟, strpos 是否不查找字符串(多字节)?有理由改用strpos吗?

There is a difference of using mb_strpos? Does't makes this work the same jobs? After all, does't strpos seek a string (multiple byte)? Is there a reason to use instead strpos?

推荐答案

对于UTF-8,匹配字节序列与匹配字符序列完全相同.

For UTF-8, matching the byte sequence is exactly the same as matching character sequence.

因此,他们两个都将在同一点找到针,但是mb_strpos在针之前计数完整的UTF-8字节序列,其中strpos计算任何字节.因此,如果您的字符串具有另一个多字节UTF-8序列,结果将有所不同:

So they both will find the needle at exactly the same point, but mb_strpos counts full UTF-8 byte sequencees before the needle, where as strpos calculates any bytes. So if your string had another multi-byte UTF-8 sequence, the results would be different:

strpos("My symbolö utf-8 is the €.", "€") !== mb_strpos("My symbolö utf-8 is the €.", "€", 0, "UTF-8")

但是:

strpos("My symbol utf-8 is the €.", "€") === mb_strpos("My symbol utf-8 is the €.", "€", 0, "UTF-8")

这篇关于mb_strpos vs strpos,有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆