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

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

      <legend id='XvCyL'><style id='XvCyL'><dir id='XvCyL'><q id='XvCyL'></q></dir></style></legend>
        • <bdo id='XvCyL'></bdo><ul id='XvCyL'></ul>

        <tfoot id='XvCyL'></tfoot>

        正则表达式从 [简码] 中提取变量

        时间:2023-06-23
        <tfoot id='g2k95'></tfoot>

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

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

                2. 本文介绍了正则表达式从 [简码] 中提取变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  将一些内容从 WordPress 迁移到 Drupal 后,我有一些短代码需要转换:

                  After migrating some content from WordPress to Drupal, I've got som shortcodes that I need to convert:

                  字符串内容:

                  无关的测试...[崇高视频类=崇高"海报="http://video.host.com/_previews/600x450/sbx-60025-00-da-ANA.png"src1="http://video.host.com/_video/H.264/LO/sbx-60025-00-da-ANA.m4v"src2="(hd)http:///video.host.com/_video/H.264/HI/sbx-60025-00-da-ANA.m4v"宽度="560" 高度="315"]..更多不相关的文字.

                  Irrelevant tekst... [sublimevideo class="sublime" poster="http://video.host.com/_previews/600x450/sbx-60025-00-da-ANA.png" src1="http://video.host.com/_video/H.264/LO/sbx-60025-00-da-ANA.m4v" src2="(hd)http://video.host.com/_video/H.264/HI/sbx-60025-00-da-ANA.m4v" width="560" height="315"] ..more irrelevant text.

                  我需要在短代码 [sublimevideo ...] 中找到所有变量并将其转换为数组:

                  I need to find all variables within the shortcode [sublimevideo ...] and turn it into an array:

                  Array (
                      class => "sublime"
                      poster => "http://video.host.com/_previews/600x450/sbx-60025-00-da-FMT.png"
                      src1 => "http://video.host.com/_video/H.264/LO/sbx-60025-00-da-FMT.m4v"
                      src2 => "(hd)http://video.host.com/_video/H.264/HI/sbx-60025-00-da-FMT.m4v"
                      width => "560"
                      height => "315"
                  )
                  

                  并且最好处理短代码的多个实例.

                  And preferably handle multiple instances of the shortcode.

                  我想它可以用 preg_match_all() 来完成,但我没有运气.

                  I guess it can be done with preg_match_all() but I've had no luck.

                  推荐答案

                  这会给你你想要的.

                  $data = 'Irrelevant tekst... [sublimevideo class="sublime" poster="http://video.host.com/_previews/600x450/sbx-60025-00-da-ANA.png" src1="http://video.host.com/_video/H.264/LO/sbx-60025-00-da-ANA.m4v" src2="(hd)http://video.host.com/_video/H.264/HI/sbx-60025-00-da-ANA.m4v" width="560" height="315"] ..more irrelevant text.';
                  
                  $dat = array();
                  preg_match("/[sublimevideo (.+?)]/", $data, $dat);
                  
                  $dat = array_pop($dat);
                  $dat= explode(" ", $dat);
                  $params = array();
                  foreach ($dat as $d){
                      list($opt, $val) = explode("=", $d);
                      $params[$opt] = trim($val, '"');
                  }
                  
                  print_r($params);
                  

                  为了应对处理短代码的下一个挑战,您可以使用 preg_replace_callback 将短标签数据替换为其结果标记.

                  In anticipation of the next challenge you will face with processing short codes you can use preg_replace_callback to replace the short tag data with it's resultant markup.

                  $data = 'Irrelevant tekst... [sublimevideo class="sublime" poster="http://video.host.com/_previews/600x450/sbx-60025-00-da-ANA.png" src1="http://video.host.com/_video/H.264/LO/sbx-60025-00-da-ANA.m4v" src2="(hd)http://video.host.com/_video/H.264/HI/sbx-60025-00-da-ANA.m4v" width="560" height="315"] ..more irrelevant text.';
                  
                  function processShortCode($matches){
                      // parse out the arguments
                      $dat= explode(" ", $matches[2]);
                      $params = array();
                      foreach ($dat as $d){
                          list($opt, $val) = explode("=", $d);
                          $params[$opt] = trim($val, '"');
                      }
                      switch($matches[1]){
                          case "sublimevideo":
                              // here is where you would want to return the resultant markup from the shorttag call.
                               return print_r($params, true);        
                      }
                  
                  }
                  $data = preg_replace_callback("/[(w+) (.+?)]/", "processShortCode", $data);
                  echo $data;
                  

                  这篇关于正则表达式从 [简码] 中提取变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在 drupal 7 中实现 hook_theme? 下一篇:dompdf 和 img 标签,图像不会显示

                  相关文章

                    • <bdo id='7bV1n'></bdo><ul id='7bV1n'></ul>

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

                      <small id='7bV1n'></small><noframes id='7bV1n'>

                      <tfoot id='7bV1n'></tfoot>