多字节函数替换preg_match_all? [英] multi-byte function to replace preg_match_all?
问题描述
我正在寻找一个多字节函数来代替preg_match_all()
.我需要一个可以给我匹配字符串的数组,例如preg_match()
中的$matches
参数.函数mb_ereg_match()
似乎没有执行此操作-它仅给我一个布尔值,指示是否存在任何匹配项.
I'm looking for a multi-byte function to replace preg_match_all()
. I need one that will give me an array of matched strings, like the $matches
argument from preg_match()
. The function mb_ereg_match()
doesn't seem to do it -- it only gives me a boolean indicating if there were any matches.
查看mb_ *函数页面,我没有随便看看可以代替preg_match()
功能的任何东西.我该怎么用?
Looking at the mb_* functions page, I don't offhand see anythng that replaces the functionality of preg_match()
. What do I use?
编辑,我是个白痴.我最初发布了这个问题,要求替换preg_match
,当然是ereg_match
.但是,这两个都只返回第一个结果.我想要的是preg_match_all
的替代品,它返回所有匹配的文本.但是无论如何,正如hakre指出的那样,u
修饰符在我的情况下对于preg_match_all
是有效的.
Edit I'm an idiot. I originally posted this question asking for a replacement for preg_match
, which of course is ereg_match
. However both those only return the first result. What I wanted was a replacement for preg_match_all
, which returns all match texts. But anyways, the u
modifier works in my case for preg_match_all
, as hakre pointed out.
推荐答案
您是否看过 mb_ereg
?
Have you taken a look into mb_ereg
?
Additionally, you can pass an UTF-8 encoded string into preg_match
using the u
modifier, which might be the kind of multbyte support you need. The other option is to encode into UTF-8 and then encode the results back.
另请参阅相关问题的答案: Are PHP preg_functions多字节安全吗?
See as well an answer to a related question: Are the PHP preg_functions multibyte safe?
这篇关于多字节函数替换preg_match_all?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!