Regex extract variables from [shortcode]

后端 未结 4 1726
礼貌的吻别
礼貌的吻别 2020-12-18 08:50

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

String content:

Irre

4条回答
  •  独厮守ぢ
    2020-12-18 09:49

    As described in this answer, I'd suggest letting WordPress do the work for you using the get_shortcode_regex() function.

     $pattern = get_shortcode_regex();
     preg_match_all("/$pattern/",$wp_content,$matches);
    

    This will give you an array that is easy to work with and shows the various shortcodes and affiliated attributes in your content. It isn't the most obvious array format, so print it and take a look so you know how to manipulate the data you need.

提交回复
热议问题