How do I preg_match for words in Hebrew

我是研究僧i 提交于 2020-01-24 11:34:05

问题


I need a function that matches full words in hebrew in php.

Please help.


回答1:


Try this regular expression describing Unicode character properties:

/\p{Hebrew}+/u



回答2:


Assuming your source data is UTF-8 encoded

$input = "ט״סת תעסתינג O״ת סOמע העברעו תעחת";

preg_match_all( "/[\\x{0590}-\\x{05FF}]+/u", $input, $matches );

echo '<pre>';
print_r( $matches );
echo '</pre>';

Yields

Array
(
    [0] => Array
        (
            [0] => ט״סת
            [1] => תעסתינג
            [2] => ״ת
            [3] => ס
            [4] => מע
            [5] => העברעו
            [6] => תעחת
        )

)

I based the range of 0590 through 05FF on this Unicode chart (edit: found more good hebrew/unicode info here). I used this to generate my sample input. Since I don't know hebrew I can't actually verify that the matched output is valid.

You may need to tweak it but hopefully this gets you headed in the right direction.




回答3:


Thanks for all your answers,

The one that works for me is preg_match("/^\p{Hebrew}+$/u", "שלום");



来源:https://stackoverflow.com/questions/1916662/how-do-i-preg-match-for-words-in-hebrew

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!