문제

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;

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?

도움이 되었습니까?

해결책

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

다른 팁

Hebrew strings use multibyte characters, so each "character" can be 2 or more characters long, and not 1, like most latin-based characters. You will probably want to look into PHP Multibyte String Functions for your application.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top