mb_ereg_search
(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)
mb_ereg_search — Multibyte regular expression match for predefined multibyte string
说明
mb_ereg_search(?string
$pattern
= null
, ?string $options
= null
): boolPerforms a multibyte regular expression match for a predefined multibyte string.
参数
-
pattern
-
The search pattern.
-
options
-
The search option. See mb_regex_set_options() for explanation.
返回值
mb_ereg_search() returns true
if the
multibyte string matches with the regular expression, or false
otherwise. The string for matching is set by
mb_ereg_search_init(). If
pattern
is not specified, the previous one
is used.
更新日志
版本 | 说明 |
---|---|
8.0.0 |
pattern and options are nullable now.
|
注释
注意:
mb_regex_encoding() 指定的内部编码或字符编码将会当作此函数用的字符编码。
参见
- mb_regex_encoding() - Set/Get character encoding for multibyte regex
- mb_ereg_search_init() - Setup string and regular expression for a multibyte regular expression match

User Contributed Notes 2 notes
dulao5 at gmail dot com ¶
15 years ago
mb_ereg_search & subpatterns
use loop:
<?php
$str = "中国abc + abc ?!?!字符# china string";
$reg = "\w+";
mb_regex_encoding("UTF-8");
mb_ereg_search_init($str, $reg);
$r = mb_ereg_search();
if(!$r)
{
echo "null\n";
}
else
{
$r = mb_ereg_search_getregs(); //get first result
do
{
var_dump($r[0]);
$r = mb_ereg_search_regs();//get next result
}
while($r);
}
?>
Christian ¶
10 months ago
A 'match_all' helper function based on dulao's answer. Someone might find it useful...
<?php
function mb_ereg_match_all($pattern, $subject, &$matches, $options = '', $setOrder = false, $offset = 0) {
if (!mb_ereg_search_init($subject, $pattern, $options)) {
return false;
}
if ($offset != 0 && !mb_ereg_search_setpos($offset)) {
return false;
}
$matches = [];
if (!mb_ereg_search()) {
return 0;
}
$regs = mb_ereg_search_getregs();
$count = 0;
do {
$count++;
if ($setOrder) {
foreach ($regs as $key => $val) {
$matches[$key][] = $val;
}
} else {
$matches[] = $regs;
}
$regs = mb_ereg_search_regs();
}
while($regs);
return $count;
}
?>
备份地址:http://www.lvesu.com/blog/php/function.mb-ereg-search.php