Iterating over matches from preg_match_all

后端 未结 2 1648
北荒
北荒 2020-12-21 09:52

I am trying to figure out the mechanics of this plugin in WordPress. I have a preg_match_all function that looks like this:

preg_match_all(\'/(?<=\\\\[\\\         


        
2条回答
  •  旧巷少年郎
    2020-12-21 10:29

    If I understand this correctly, count($matches[0] assumes there is only one match in $content.

    Not quite; $matches[0] represents the array of matches in of the whole regular expression (as opposed to, say, $matches[1], which would be the array of matches in the first match group of the regular expression). Thus, count($matches[0]) is the number of matches in he first match group.

    You could do what you've said and rewrite the for loop as a foreach loop, but this likely won't change anything, as both methods should traverse all elements in $matches[0]. Are you certain that the results you're looking for are matched in your regular expression?

提交回复
热议问题