Heim  >  Artikel  >  Backend-Entwicklung  >  一个php查找问题

一个php查找问题

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

$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_ 获取自然长度

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn