1. <tfoot id='X6u3h'></tfoot>
        • <bdo id='X6u3h'></bdo><ul id='X6u3h'></ul>

        <i id='X6u3h'><tr id='X6u3h'><dt id='X6u3h'><q id='X6u3h'><span id='X6u3h'><b id='X6u3h'><form id='X6u3h'><ins id='X6u3h'></ins><ul id='X6u3h'></ul><sub id='X6u3h'></sub></form><legend id='X6u3h'></legend><bdo id='X6u3h'><pre id='X6u3h'><center id='X6u3h'></center></pre></bdo></b><th id='X6u3h'></th></span></q></dt></tr></i><div id='X6u3h'><tfoot id='X6u3h'></tfoot><dl id='X6u3h'><fieldset id='X6u3h'></fieldset></dl></div>
      2. <legend id='X6u3h'><style id='X6u3h'><dir id='X6u3h'><q id='X6u3h'></q></dir></style></legend>

        <small id='X6u3h'></small><noframes id='X6u3h'>

        迭代来自 preg_match_all 的匹配项

        时间:2023-09-21
      3. <tfoot id='ooO1T'></tfoot>
          <tbody id='ooO1T'></tbody>

        1. <i id='ooO1T'><tr id='ooO1T'><dt id='ooO1T'><q id='ooO1T'><span id='ooO1T'><b id='ooO1T'><form id='ooO1T'><ins id='ooO1T'></ins><ul id='ooO1T'></ul><sub id='ooO1T'></sub></form><legend id='ooO1T'></legend><bdo id='ooO1T'><pre id='ooO1T'><center id='ooO1T'></center></pre></bdo></b><th id='ooO1T'></th></span></q></dt></tr></i><div id='ooO1T'><tfoot id='ooO1T'></tfoot><dl id='ooO1T'><fieldset id='ooO1T'></fieldset></dl></div>
            <bdo id='ooO1T'></bdo><ul id='ooO1T'></ul>
          • <small id='ooO1T'></small><noframes id='ooO1T'>

            <legend id='ooO1T'><style id='ooO1T'><dir id='ooO1T'><q id='ooO1T'></q></dir></style></legend>

                  本文介绍了迭代来自 preg_match_all 的匹配项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想弄清楚这个插件在 WordPress 中的机制.我有一个看起来像这样的 preg_match_all 函数:

                  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];
                  }
                  

                  如果我理解正确,count($matches[0]) 假设 $content 中只有一个匹配项.

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

                  我的目标是重新编写 for 语句以允许 preg_match_all 脚本中的完整匹配数组.

                  My goal here is to re-write the for statement to allow for the full array of matches in the preg_match_all script.

                  我假设我应该用 foreach ($matches as $postSlug) 替换 for 语句,甚至不打扰令人困惑的 $matches[0][$i]代码>在最后.

                  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!

                  推荐答案

                  如果我理解正确,count($matches[0] 假设 $content 中只有一个匹配项.

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

                  不完全是;$matches[0] 表示整个正则表达式中的匹配数组(而不是 $matches[1],它是匹配数组在正则表达式的第一个匹配组中).因此,count($matches[0]) 是第一个匹配组中的匹配数.

                  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.

                  你可以按照你说的做,将 for 循环重写为 foreach 循环,但这可能不会改变任何东西,因为这两种方法都应该遍历所有$matches[0] 中的元素.您确定您要查找的结果与您的正则表达式匹配吗?

                  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?

                  这篇关于迭代来自 preg_match_all 的匹配项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何乘数直到达到个位数并计算数字? 下一篇:如何将多个数组插入到数据库中?

                  相关文章

                  最新文章

                    <bdo id='W4fza'></bdo><ul id='W4fza'></ul>

                    <small id='W4fza'></small><noframes id='W4fza'>

                  1. <i id='W4fza'><tr id='W4fza'><dt id='W4fza'><q id='W4fza'><span id='W4fza'><b id='W4fza'><form id='W4fza'><ins id='W4fza'></ins><ul id='W4fza'></ul><sub id='W4fza'></sub></form><legend id='W4fza'></legend><bdo id='W4fza'><pre id='W4fza'><center id='W4fza'></center></pre></bdo></b><th id='W4fza'></th></span></q></dt></tr></i><div id='W4fza'><tfoot id='W4fza'></tfoot><dl id='W4fza'><fieldset id='W4fza'></fieldset></dl></div>

                  2. <tfoot id='W4fza'></tfoot>

                      <legend id='W4fza'><style id='W4fza'><dir id='W4fza'><q id='W4fza'></q></dir></style></legend>