PREG_SET_ORDER:
结果排序为
$matches
[0]包含第一次匹配得到的所有匹配(包含子组)
,
$matches
[1]是包含第
二次匹配到的所有匹配(包含子组)的数组,以此类推。
PREG_OFFSET_CAPTURE:
如果这个标记被传递,每个发现的匹配返回时会增加它相对目标字符串的偏移量。 注意
这会改变 matches
中的每一个匹配结果字符串元素,使其 成为一个第 0
个元素为 匹配结
果字符串,第 1
个元素为 匹配结果字符串在 subject 中的偏移量。
返回值:
返回完整匹配次数(可能是 0),或者如果发生错误返回 FALSE。
示例:
复制代码 代码如下:
<?php
/*
*将会输出:2
*/
echo
preg_match_all("/php/i", "In my point, PHP is the web scripting language of choice. I love
php",
$matches
);
echo
"<br/>"."\n";
/*
*将会输出:Array([0]=>, PHP [1]=>PHP)
*/
$matches
=
array
();
preg_match("/[,a-z]?\s*(php)/i", "In my point, PHP is the web scripting language of choice. I love
php",
$matches
);
print_r(
$matches
);
echo
"<br/>"."\n";
/*
*将会输出:Array([0]=>Array([0]=>, PHP [1]=>e php) [1]=>Array([0]=>PHP [1]=>php))
*/
$matches
=
array
();
preg_match_all("/[,a-z]?\s*(php)/i", "In my point, PHP is the web scripting language of choice. I
love php",
$matches
, PREG_PATTERN_ORDER);
print_r(
$matches
);
echo
"<br/>"."\n";
/*
*将会输出:Array([0]=>Array([0]=>Array([0]=>, PHP [1]=>11) [1]=>Array([0]=>PHP [1]=>13))
[1]=>Array([0]=>Array([0]=>e php [1]=>63) [1]=>Array([0]=>php [1]=>65)))
*/
$matches
=
array
();
preg_match_all("/[,a-z]?\s*(php)/i", "In my point, PHP is the web scripting language of choice. I