本文介绍了strpos在希伯来语中返回错误的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助...我有希伯来语php字符串,我想搜索子字符串的位置.我的代码:

I need help...I have hebrew php string and I want search position of substring.my code:

$string = "אבגד הוזח טי";
$find = "הוזח";
$pos = strpos($string, $find);
echo $pos;

strpos找到了子字符串,但是返回了错误的position值.它返回$ pos值9而不是5.为什么strpos在希伯来语字符串中不起作用?你能帮我吗?

The strpos found the substring, but return wrong value of position.It return $pos value 9 Instead of 5.Why the strpos not working in hebrew strings?Can you help me please?

推荐答案

尝试使用 mb_strpos .您将必须使用 mb_internal_encoding .

Try using mb_strpos. You will have to set your internal character encoding to UTF-8 using mb_internal_encoding.

mb_internal_encoding("UTF-8");
$string = "אבגד הוזח טי";
$find = "הוזח";
$pos = mb_strpos($string, $find);
echo $pos; //5

这篇关于strpos在希伯来语中返回错误的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-26 21:56