0
例数组项的字符串:匹配其中包含与preg_match_all
我有这样的字符串
" [mc_gross] => 50.00 [invoice] => done [address_details] => xyz [protection_eligibility] => Eligible"
所以,我已经使用下面的代码。
preg_match_all("/^\s{2}\[(.+?)\] \=\> /m", $in, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);
Preg_match_all返回空数组,但我想返回类似下面的数组的偏移值:
Array
(
[0] => Array
(
[0] => Array
(
[0] => [mc_gross] =>
[1] => 0
)
[1] => Array
(
[0] => mc_gross
[1] => 3
)
)
[1] => Array
(
[0] => Array
(
[0] => [invoice] =>
[1] => 21
)
[1] => Array
(
[0] => invoice
[1] => 24
)
)
)
,这样我可以测试下面的代码:
foreach($matches as $match) {
$key = $match[1][0]; // matched string
$offset = $match[0][1]; // starting point of the matched string
// start returns starting point of matched string + string length of matched string
$start = $match[0][1] + strlen($match[0][0]);
}
秀应该如何看待预期结果 – RomanPerekhrest
我想帮助你,但是你的过程的总体目标是什么?你是否试图根据值的长度来验证字符串? – mickmackusa