Home  >  Article  >  Backend Development  >  一个php查找问题

一个php查找问题

WBOY
WBOYOriginal
2016-06-06 20:46:371051browse

$a = '辣fdsfd4352椒素的林凤娇阿隆索丹甫股份fds啊';
$b = '素' 怎么查到他在第12个

回复内容:

$a = '辣fdsfd4352椒素的林凤娇阿隆索丹甫股份fds啊';
$b = '素' 怎么查到他在第12个

撸主问的是出现 12,基于上面同学的贡献纠正下答案:

<code class="lang-php">$a = '辣fdsfd4352椒素的林凤娇阿隆索丹甫股份fds啊';
$b = '素';
$char_pos = strpos($a, $b);   // 15

// 查找中文位置,需要结合 mb* 函数
mb_internal_encoding('UTF-8');
$pos = mb_strpos($a, $b) + 1; // 12
</code>

<code>$a = '辣fdsfd4352椒素的林凤娇阿隆索丹甫股份fds啊';
$b = '素';
$pos = strpos($a, $b);
</code>

<code>    strpos($a, $b);
</code>

mb_ 获取自然长度

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn