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('/(?<=\[\[).+?(?=\]\])/', $content, $matches, PREG_PATTERN_ORDER);
$numMatches = count($matches[0]);
for ($i = 0; $i < $numMatches; $i++) {
$postSlug = $matches[0][$i];
}
If I understand this correctly, count($matches[0])
assumes there is only one match in $content
.
My goal here is to re-write the for statement to allow for the full array of matches in the preg_match_all
script.
I'm assuming I should replace the for statement with foreach ($matches as $postSlug)
and not even bother with the confusing $matches[0][$i]
at the end.
Unfortunately the final output does not seem to loop through each element in the array. Any ideas? Thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…