UTF-8 characters in preg_match_all (PHP)

后端 未结 4 893
花落未央
花落未央 2020-12-17 19:34

I have preg_match_all(\'/[aäeëioöuáéíóú]/u\', $in, $out, PREG_OFFSET_CAPTURE);

If $in = \'hëllo\' $out is:

arr         


        
4条回答
  •  粉色の甜心
    2020-12-17 19:47

    PHP doesn't support unicode very well, so a lot of string functions, including preg_*, still count bytes instead of characters.

    I tried finding a solution by encoding and decoding strings, but ultimately it all came down to the preg_match_all function.

    About the python thing: a python regex matchobject contains the match position by default mo.start() and mo.end(). See: http://docs.python.org/library/re.html#finding-all-adverbs-and-their-positions

提交回复
热议问题