UTF-8 characters in preg_match_all (PHP)

后端 未结 4 901
花落未央
花落未央 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 20:03

    There is simple workaround, to be used after preg_match() results matched. You need to iterate every match result and reassign position value with following:

    $utfPosition = mb_strlen(substr($wholeSubjectString, 0, $capturedEntryPosition), 'utf-8');
    

    Tested on php 5.4 under Windows, depends on Multibyte PHP extension only.

提交回复
热议问题