提取短代码中的字符串

时间:2014-03-10 14:41:13

标签: php wordpress

我有一个字符串,可能包含this is a string [e]with[/e] multiple [e]shortcodes[/e]等短代码。我想提取字符串:“with”和“shortcodes”到数组中。

$string_with_shortcodes = "this is a string [e]with[/e] multiple [e]shortcodes[/e]";

我该怎么做?

1 个答案:

答案 0 :(得分:0)

$count = preg_match_all("\01\[e\](.*?)\[/e\]\01", $string_with_shortcodes, $matches);
$shortcodes_array = $matches[1];

根据您提供的示例,

  • $matches[0]将包含:Array("[e]with[/e]","[e]shortcodes[/e]")
  • $matches[1]将包含:Array("with","shortcodes")