Php 提取短代码内的字符串

Php 提取短代码内的字符串,php,wordpress,Php,Wordpress,我有一个可能包含短码的字符串,例如,这是一个包含多个[e]短码的字符串[e]。我想将字符串:“with”和“shortcode”提取到一个数组中 $string_with_shortcodes = "this is a string [e]with[/e] multiple [e]shortcodes[/e]"; 我该怎么做 $count = preg_match_all("\01\[e\](.*?)\[/e\]\01", $string_with_shortcodes, $matches);

我有一个可能包含短码的字符串,例如
,这是一个包含多个[e]短码的字符串[e]
。我想将字符串:“with”和“shortcode”提取到一个数组中

$string_with_shortcodes = "this is a string [e]with[/e] multiple [e]shortcodes[/e]";
我该怎么做

$count = preg_match_all("\01\[e\](.*?)\[/e\]\01", $string_with_shortcodes, $matches);
$shortcodes_array = $matches[1];
根据你举的例子

  • $matches[0]
    将包含:
    数组(“[e]带[/e]”,“[e]短码[/e]”)
  • $matches[1]
    将包含:
    数组(“带”、“短代码”)

@Liso22,不能省略
$matches[0]
。它包含完整的原始匹配模式。