多字节函数替换preg_match_all? [英] multi-byte function to replace preg_match_all?

查看:160
本文介绍了多字节函数替换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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆